You are here

public function SubformState::conditionalElement in Markdown 8.2

{@inheritdoc

Overrides SubformStateInterface::conditionalElement

File

src/Form/SubformState.php, line 31

Class

SubformState
Markdown subform state.

Namespace

Drupal\markdown\Form

Code

public function conditionalElement(array $element, $state, $name, array $conditions) {
  $element += [
    '#type' => 'html_tag',
  ];
  if ($element['#type'] === 'container') {
    $element += [
      '#theme_wrappers' => [
        'container__markdown_conditional_element__' . $name,
      ],
    ];
  }
  if ($element['#type'] === 'html_tag') {
    $element += [
      '#tag' => 'span',
    ];
  }
  $element['#attributes']['class'][] = 'js-form-item';
  $this
    ->addElementState($element, $state, $name, $conditions);

  // Older versions of Drupal core do not have the necessary helper method:
  // \Drupal\Core\Form\FormHelper::processStates. Instead of completely
  // back-porting that entire class, we'll just do what it does here.
  // @todo Replace with FormHelper::processStates() in D9.
  $element['#attached']['library'][] = 'core/drupal.states';
  $element['#attributes']['data-drupal-states'] = Json::encode($element['#states']);
  return drupal_render($element);
}