コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $element = parent::settingsForm($form, $form_state);
     $browsers = [];
     /** @var \Drupal\entity_browser\EntityBrowserInterface $browser */
     foreach ($this->entityManager->getStorage('entity_browser')->loadMultiple() as $browser) {
         $browsers[$browser->id()] = $browser->label();
     }
     $element['entity_browser'] = ['#title' => t('Entity browser'), '#type' => 'select', '#default_value' => $this->getSetting('entity_browser'), '#options' => $browsers];
     $target_type = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('target_type');
     $entity_type = \Drupal::entityTypeManager()->getStorage($target_type)->getEntityType();
     $displays = [];
     foreach ($this->fieldDisplayManager->getDefinitions() as $id => $definition) {
         if ($this->fieldDisplayManager->createInstance($id)->isApplicable($entity_type)) {
             $displays[$id] = $definition['label'];
         }
     }
     $id = Html::getUniqueId('field-' . $this->fieldDefinition->getName() . '-display-settings-wrapper');
     $element['field_widget_display'] = ['#title' => t('Entity display plugin'), '#type' => 'select', '#default_value' => $this->getSetting('field_widget_display'), '#options' => $displays, '#ajax' => ['callback' => array($this, 'updateSettingsAjax'), 'wrapper' => $id]];
     $element['field_widget_edit'] = ['#title' => t('Display Edit button'), '#type' => 'checkbox', '#default_value' => $this->getSetting('field_widget_edit')];
     $element['field_widget_remove'] = ['#title' => t('Display Remove button'), '#type' => 'checkbox', '#default_value' => $this->getSetting('field_widget_remove')];
     $element['open'] = ['#title' => t('Show widget details as open by default'), '#type' => 'checkbox', '#default_value' => $this->getSetting('open')];
     $element['field_widget_display_settings'] = ['#type' => 'fieldset', '#title' => t('Entity display plugin configuration'), '#tree' => TRUE, '#prefix' => '<div id="' . $id . '">', '#suffix' => '</div>'];
     if ($this->getSetting('field_widget_display')) {
         $element['field_widget_display_settings'] += $this->fieldDisplayManager->createInstance($form_state->getValue(['fields', $this->fieldDefinition->getName(), 'settings_edit_form', 'settings', 'field_widget_display'], $this->getSetting('field_widget_display')), $form_state->getValue(['fields', $this->fieldDefinition->getName(), 'settings_edit_form', 'settings', 'field_widget_display_settings'], $this->getSetting('field_widget_display_settings')) + ['entity_type' => $this->fieldDefinition->getFieldStorageDefinition()->getSetting('target_type')])->settingsForm($form, $form_state);
     }
     return $element;
 }
コード例 #2
0
ファイル: MultiStepDisplay.php プロジェクト: jepster/GaiaD8
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $default_entity_type = $form_state->getValue('entity_type', $this->configuration['entity_type']);
     $default_display = $form_state->getValue('display', $this->configuration['display']);
     $default_display_settings = $form_state->getValue('display_settings', $this->configuration['display_settings']);
     $default_display_settings += ['entity_type' => $default_entity_type];
     $form['#prefix'] = '<div id="multi-step-form-wrapper">';
     $form['#suffix'] = '</div>';
     $entity_types = [];
     foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
         /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
         $entity_types[$entity_type_id] = $entity_type->getLabel();
     }
     $form['entity_type'] = ['#type' => 'select', '#title' => $this->t('Entity type'), '#description' => $this->t("Entity browser itself does not need information about entity type being selected. It can actually select entities of different type. However, some of the display plugins need to know which entity type they are operating with. Display plugins that do not need this info will ignore this configuration value."), '#default_value' => $default_entity_type, '#options' => $entity_types, '#ajax' => ['callback' => [$this, 'updateSettingsAjax'], 'wrapper' => 'multi-step-form-wrapper']];
     $displays = [];
     foreach ($this->fieldDisplayManager->getDefinitions() as $display_plugin_id => $definition) {
         $entity_type = $this->entityManager->getDefinition($default_entity_type);
         if ($this->fieldDisplayManager->createInstance($display_plugin_id)->isApplicable($entity_type)) {
             $displays[$display_plugin_id] = $definition['label'];
         }
     }
     $form['display'] = ['#title' => t('Entity display plugin'), '#type' => 'select', '#default_value' => $default_display, '#options' => $displays, '#ajax' => ['callback' => [$this, 'updateSettingsAjax'], 'wrapper' => 'multi-step-form-wrapper']];
     $form['display_settings'] = ['#type' => 'container', '#title' => t('Entity display plugin configuration'), '#tree' => TRUE];
     if ($default_display_settings) {
         $display_plugin = $this->fieldDisplayManager->createInstance($default_display, $default_display_settings);
         $form['display_settings'] += $display_plugin->settingsForm($form, $form_state);
     }
     return $form;
 }