You are here

public function EntityField::blockForm in Chaos Tool Suite (ctools) 8.3

Overrides BlockPluginTrait::blockForm

File

modules/ctools_block/src/Plugin/Block/EntityField.php, line 204

Class

EntityField
Provides a block to a field on an entity.

Namespace

Drupal\ctools_block\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $config = $this
    ->getConfiguration();
  $form['formatter_label'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Label'),
    '#options' => [
      'above' => $this
        ->t('Above'),
      'inline' => $this
        ->t('Inline'),
      'hidden' => '- ' . $this
        ->t('Hidden') . ' -',
      'visually_hidden' => '- ' . $this
        ->t('Visually Hidden') . ' -',
    ],
    '#default_value' => $config['formatter']['label'],
  ];
  $form['formatter_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Formatter'),
    '#options' => $this
      ->getFormatterOptions(),
    '#default_value' => $config['formatter']['type'],
    '#ajax' => [
      'callback' => [
        static::class,
        'formatterSettingsAjaxCallback',
      ],
      'wrapper' => 'formatter-settings-wrapper',
      'effect' => 'fade',
    ],
  ];

  // Add the formatter settings to the form via AJAX.
  $form['#process'][] = [
    $this,
    'formatterSettingsProcessCallback',
  ];
  $form['formatter_settings_wrapper'] = [
    '#prefix' => '<div id="formatter-settings-wrapper">',
    '#suffix' => '</div>',
  ];
  $form['formatter_settings_wrapper']['formatter_settings'] = [
    '#tree' => TRUE,
  ];
  return $form;
}