예제 #1
0
 /**
  * Gets an instance of a formatter.
  *
  * @param array $options
  *   Formatter options.
  *
  * @return \Drupal\Core\Field\FormatterInterface
  */
 protected function getFormatter($options)
 {
     if (!isset($options['settings'])) {
         $options['settings'] = array();
     }
     $options += array('field_definition' => $this->fieldDefinition, 'view_mode' => $this->viewMode, 'configuration' => array('type' => $options['id'], 'settings' => $options['settings']));
     return $this->formatterManager->getInstance($options);
 }
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     $this->addDependencies(parent::calculateDependencies());
     $definition = $this->formatterPluginManager->getDefinition($this->getDerivativeId());
     $this->addDependency('module', $definition['provider']);
     // @todo Investigate why this does not work currently.
     //$this->calculatePluginDependencies($this->getFieldFormatter());
     return $this->dependencies;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     $dependencies = parent::calculateDependencies();
     // Add the module providing the configured field storage as a dependency.
     if (($field_storage_definition = $this->getFieldStorageDefinition()) && $field_storage_definition instanceof EntityInterface) {
         $dependencies['config'][] = $field_storage_definition->getConfigDependencyName();
     }
     // Add the module providing the formatter.
     if (!empty($this->options['type'])) {
         $dependencies['module'][] = $this->formatterPluginManager->getDefinition($this->options['type'])['provider'];
     }
     return $dependencies;
 }
예제 #4
0
파일: EntityField.php 프로젝트: Wylbur/gj
 /**
  * Gets the formatter object.
  *
  * @param string $type
  *   The formatter name.
  * @param string $label
  *   The label option for the formatter.
  * @param array $settings
  *   The formatter settings.
  * @param array $third_party_settings
  *   The formatter third party settings.
  *
  * @return \Drupal\Core\Field\FormatterInterface
  *   The formatter object.
  */
 protected function getFormatter($type, $label, array $settings, array $third_party_settings)
 {
     return $this->formatterManager->createInstance($type, ['field_definition' => $this->getFieldDefinition(), 'view_mode' => 'default', 'prepare' => TRUE, 'label' => $label, 'settings' => $settings, 'third_party_settings' => $third_party_settings]);
 }
예제 #5
0
파일: Field.php 프로젝트: alnutile/drunatra
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, &$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' => t('Column used for click sorting'), '#options' => array_combine($column_names, $column_names), '#default_value' => $this->options['click_sort_column'], '#description' => 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' => t('Formatter'), '#options' => $formatters, '#default_value' => $this->options['type'], '#ajax' => array('path' => views_ui_build_form_path($form_state)), '#submit' => array(array($this, 'submitTemporaryForm')), '#executes_submit_callback' => TRUE);
     $form['field_api_classes'] = array('#title' => t('Use field template'), '#type' => 'checkbox', '#default_value' => $this->options['field_api_classes'], '#description' => 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'] .= ' ' . 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);
     }
     $form['settings'] = $settings_form;
 }