Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $field = $this->getFieldDefinition();
     $formatters = $this->formatterPluginManager->getOptions($field->getType());
     $column_names = array_keys($field->getColumns());
     // If this is a multiple value field, add its options.
     if ($this->multiple) {
         $this->multiple_options_form($form, $form_state);
     }
     // No need to ask the user anything if the field has only one column.
     if (count($field->getColumns()) == 1) {
         $form['click_sort_column'] = array('#type' => 'value', '#value' => isset($column_names[0]) ? $column_names[0] : '');
     } else {
         $form['click_sort_column'] = array('#type' => 'select', '#title' => $this->t('Column used for click sorting'), '#options' => array_combine($column_names, $column_names), '#default_value' => $this->options['click_sort_column'], '#description' => $this->t('Used by Style: Table to determine the actual column to click sort the field on. The default is usually fine.'));
     }
     $form['type'] = array('#type' => 'select', '#title' => $this->t('Formatter'), '#options' => $formatters, '#default_value' => $this->options['type'], '#ajax' => array('url' => views_ui_build_form_url($form_state)), '#submit' => array(array($this, 'submitTemporaryForm')), '#executes_submit_callback' => TRUE);
     $form['field_api_classes'] = array('#title' => $this->t('Use field template'), '#type' => 'checkbox', '#default_value' => $this->options['field_api_classes'], '#description' => $this->t('If checked, field api classes will be added by field templates. This is not recommended unless your CSS depends upon these classes. If not checked, template will not be used.'), '#fieldset' => 'style_settings', '#weight' => 20);
     if ($this->multiple) {
         $form['field_api_classes']['#description'] .= ' ' . $this->t('Checking this option will cause the group Display Type and Separator values to be ignored.');
     }
     // Get the currently selected formatter.
     $format = $this->options['type'];
     $settings = $this->options['settings'] + $this->formatterPluginManager->getDefaultSettings($format);
     $options = array('field_definition' => $field, 'configuration' => array('type' => $format, 'settings' => $settings, 'label' => '', 'weight' => 0), 'view_mode' => '_custom');
     // Get the settings form.
     $settings_form = array('#value' => array());
     if ($formatter = $this->formatterPluginManager->getInstance($options)) {
         $settings_form = $formatter->settingsForm($form, $form_state);
         // Convert field UI selector states to work in the Views field form.
         FormHelper::rewriteStatesSelector($settings_form, "fields[{$field->getName()}][settings_edit_form]", 'options');
     }
     $form['settings'] = $settings_form;
 }
Beispiel #2
0
 /**
  * Returns the field formatter instance.
  *
  * @return \Drupal\Core\Field\FormatterInterface|null
  *   The field formatter instance.
  */
 protected function getFormatterInstance($format = NULL)
 {
     if (!isset($format)) {
         $format = $this->options['type'];
     }
     $settings = $this->options['settings'] + $this->formatterPluginManager->getDefaultSettings($format);
     $options = ['field_definition' => $this->getFieldDefinition(), 'configuration' => ['type' => $format, 'settings' => $settings, 'label' => '', 'weight' => 0], 'view_mode' => '_custom'];
     return $this->formatterPluginManager->getInstance($options);
 }
 /**
  * {@inheritdoc}
  */
 public function defaultConfiguration()
 {
     return $this->formatterPluginManager->getDefaultSettings($this->getDerivativeId());
 }