You are here

public function CopyFieldForm::buildForm in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 src/Form/CopyFieldForm.php \Drupal\ds\Form\CopyFieldForm::buildForm()
  2. 8.3 src/Form/CopyFieldForm.php \Drupal\ds\Form\CopyFieldForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides FieldFormBase::buildForm

File

src/Form/CopyFieldForm.php, line 27

Class

CopyFieldForm
Configure block fields.

Namespace

Drupal\ds\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $field_key = '') {
  $form = parent::buildForm($form, $form_state, $field_key);
  $field = $this->field;
  $manager = \Drupal::service('plugin.manager.ds');
  $fields = [];
  foreach ($manager
    ->getDefinitions() as $plugin_id => $plugin_definition) {
    $entity_label = '';
    if (isset($plugin_definition['entity_type'])) {
      $entity_label .= ucfirst(str_replace('_', ' ', $plugin_definition['entity_type'])) . ' - ';
    }
    $fields[$plugin_id] = $entity_label . $plugin_definition['title'];
  }
  asort($fields);
  $form['ds_field_identity']['ds_plugin'] = [
    '#type' => 'select',
    '#options' => $fields,
    '#title' => $this
      ->t('Fields'),
    '#required' => TRUE,
    '#default_value' => isset($field['properties']['ds_plugin']) ? $field['properties']['ds_plugin'] : '',
  ];
  return $form;
}