You are here

public function ChangeFormDisplay::getSettingsForm in Business Rules 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/BusinessRulesAction/ChangeFormDisplay.php \Drupal\business_rules\Plugin\BusinessRulesAction\ChangeFormDisplay::getSettingsForm()

Return the form array.

@internal param array $form

Parameters

array $form: The form array.

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

\Drupal\business_rules\ItemInterface $item: The configured item.

Return value

array The render array for the settings form.

Overrides BusinessRulesItemPluginBase::getSettingsForm

File

src/Plugin/BusinessRulesAction/ChangeFormDisplay.php, line 32

Class

ChangeFormDisplay
Class ChangeFormDisplay.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

public function getSettingsForm(array &$form, FormStateInterface $form_state, ItemInterface $item) {
  if ($item
    ->isNew()) {
    return [];
  }
  $form_modes = \Drupal::service('entity_display.repository')
    ->getFormModes($item
    ->getTargetEntityType());
  $options = [];
  foreach ($form_modes as $key => $value) {
    $options[$key] = $value['label'];
  }
  uasort($options, function ($a, $b) {
    return $a['label'] < $b['label'] ? -1 : 1;
  });
  $settings['selection_mode'] = [
    '#type' => 'radios',
    '#title' => t('Selection mode'),
    '#description' => t('How do you want to set the form display mode?'),
    '#default_value' => $item
      ->getSettings('selection_mode'),
    '#required' => TRUE,
    '#options' => [
      'fixed' => t('Fixed'),
      'variable' => t('Using variables or token'),
    ],
  ];
  $settings['fixed'] = [
    '#type' => 'select',
    '#title' => t('Form Mode'),
    '#default_value' => $item
      ->getSettings('fixed'),
    '#options' => $options,
    '#empty_option' => t('- Select -'),
    '#states' => [
      'visible' => [
        ':input[name="selection_mode"]' => [
          'value' => 'fixed',
        ],
      ],
    ],
  ];
  $settings['variable'] = [
    '#type' => 'textfield',
    '#title' => t('Variable or token'),
    '#description' => t('The variable/token must hold the value of the view mode id without the entity type.'),
    '#default_value' => $item
      ->getSettings('variable'),
    '#states' => [
      'visible' => [
        ':input[name="selection_mode"]' => [
          'value' => 'variable',
        ],
      ],
    ],
  ];
  return $settings;
}