You are here

protected function BaseParser::renderStrategyDisabledSettingState in Markdown 8.2

Adds a conditional state for a setting element based on render strategy.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The current form state.

array $element: The element to modify, passed by reference.

string|string[] $state: Optional. Additional states to trigger when setting is disabled, e.g. unchecked, etc.

array $conditions: The conditions for which to trigger the state(s).

3 calls to BaseParser::renderStrategyDisabledSettingState()
CommonMark::buildConfigurationForm in src/Plugin/Markdown/CommonMark/CommonMark.php
Form constructor.
Parsedown::buildConfigurationForm in src/Plugin/Markdown/Parsedown/Parsedown.php
Form constructor.
PhpMarkdown::buildConfigurationForm in src/Plugin/Markdown/PhpMarkdown/PhpMarkdown.php
Form constructor.

File

src/Plugin/Markdown/BaseParser.php, line 310

Class

BaseParser
Base class form Markdown Parser instances.

Namespace

Drupal\markdown\Plugin\Markdown

Code

protected function renderStrategyDisabledSettingState(FormStateInterface $form_state, array &$element, $state = 'disabled', array $conditions = [
  '!value' => self::NONE,
]) {

  /** @var \Drupal\markdown\Form\SubformStateInterface $form_state */
  $markdownParents = $form_state
    ->get('markdownSubformParents');
  $parents = array_merge($markdownParents, [
    'render_strategy',
    'type',
  ]);
  $selector = ':input[name="' . array_shift($parents) . '[' . implode('][', $parents) . ']"]';
  $states = (array) $state;
  foreach ($states as $state) {
    $form_state
      ->addElementState($element, $state, $selector, $conditions);
  }

  // Add a conditional description explaining why the setting is disabled.
  if (!isset($element['#description'])) {
    $element['#description'] = $this
      ->renderStrategyDisabledSetting($form_state);
  }
  else {
    $element['#description'] = new FormattableMarkup('@description @renderStrategyDisabledSetting', [
      '@description' => $element['#description'],
      '@renderStrategyDisabledSetting' => $this
        ->renderStrategyDisabledSetting($form_state),
    ]);
  }
}