Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ be achieved with this CSS selector:
```css
:not(.json-forms-description-tooltip)
```
### Custom CSS Classes

For any control and layout it is possible to specify CSS classes in the UI
schema that will be added to the generated HTML code. The classes can be set at
the property `cssClasses` in the `options` property, e.g.:

```json
{
"type": "VerticalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/name",
"options": {
"cssClasses": ["my-name-control-class"]
}
}
],
"options": {
"cssClasses": ["my-layout-class"]
}
}
```

## Limitations

Expand Down
7 changes: 7 additions & 0 deletions src/Form/FormArrayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public function createFormArray(DefinitionInterface $definition, FormStateInterf
$formState->set(['form', $definition->getPropertyFormName()], $form);
}

// @phpstan-ignore offsetAccess.nonOffsetAccessible
$form['#attributes']['class'] =
// @phpstan-ignore binaryOp.invalid
($definition->getOptionsValue('cssClasses') ?? []) +
// @phpstan-ignore offsetAccess.nonOffsetAccessible
($form['#attributes']['class'] ?? []);

return $form;
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/JsonForms/Definition/Control/ControlDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,7 @@ public function getOptions(): ?\stdClass {
return $this->controlSchema->options ?? NULL;
}

/**
* @param string $key
* @param mixed $default
*
* @return mixed
*/
public function getOptionsValue(string $key, $default = NULL) {
public function getOptionsValue(string $key, mixed $default = NULL): mixed {
return $this->controlSchema->options->{$key} ?? $default;
}

Expand Down
9 changes: 9 additions & 0 deletions src/JsonForms/Definition/Custom/CustomDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public function __construct(
$this->rootDefinition = $rootDefinition ?? $this;
}

public function getOptions(): ?\stdClass {
return $this->uiSchema->options ?? NULL;
}

public function getOptionsValue(string $key, mixed $default = NULL): mixed {
// @phpstan-ignore property.dynamicName
return $this->uiSchema->options->{$key} ?? $default;
}

/**
* {@inheritDoc}
*/
Expand Down
9 changes: 9 additions & 0 deletions src/JsonForms/Definition/Custom/MarkupDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public function getContentMediaType(): string {
return $this->markupSchema->contentMediaType;
}

public function getOptions(): ?\stdClass {
return $this->markupSchema->options ?? NULL;
}

public function getOptionsValue(string $key, mixed $default = NULL): mixed {
// @phpstan-ignore property.dynamicName
return $this->markupSchema->options->{$key} ?? $default;
}

/**
* {@inheritDoc}
*/
Expand Down
4 changes: 4 additions & 0 deletions src/JsonForms/Definition/DefinitionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

interface DefinitionInterface {

public function getOptions(): ?\stdClass;

public function getOptionsValue(string $key, mixed $default = NULL): mixed;

/**
* @param mixed $default
*
Expand Down
8 changes: 1 addition & 7 deletions src/JsonForms/Definition/Layout/LayoutDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,7 @@ public function getOptions(): ?\stdClass {
return $this->layoutSchema->options ?? NULL;
}

/**
* @param string $key
* @param mixed $default
*
* @return mixed
*/
public function getOptionsValue(string $key, $default = NULL) {
public function getOptionsValue(string $key, mixed $default = NULL): mixed {
return $this->layoutSchema->options->{$key} ?? $default;
}

Expand Down