You are here

protected function EntityField::defineOptions in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/field/EntityField.php \Drupal\views\Plugin\views\field\EntityField::defineOptions()

Information about options for all kinds of purposes will be held here.


'option_name' => array(
 - 'default' => default value,
 - 'contains' => (optional) array of items this contains, with its own
     defaults, etc. If contains is set, the default will be ignored and
     assumed to be array().
 ),

Return value

array Returns the options of this handler/plugin.

Overrides FieldPluginBase::defineOptions

1 call to EntityField::defineOptions()
TermName::defineOptions in core/modules/taxonomy/src/Plugin/views/field/TermName.php
Information about options for all kinds of purposes will be held here.
1 method overrides EntityField::defineOptions()
TermName::defineOptions in core/modules/taxonomy/src/Plugin/views/field/TermName.php
Information about options for all kinds of purposes will be held here.

File

core/modules/views/src/Plugin/views/field/EntityField.php, line 378

Class

EntityField
A field that displays entity field data.

Namespace

Drupal\views\Plugin\views\field

Code

protected function defineOptions() {
  $options = parent::defineOptions();
  $field_storage_definition = $this
    ->getFieldStorageDefinition();
  $field_type = $this->fieldTypePluginManager
    ->getDefinition($field_storage_definition
    ->getType());
  $column_names = array_keys($field_storage_definition
    ->getColumns());
  $default_column = '';

  // Try to determine a sensible default.
  if (count($column_names) == 1) {
    $default_column = $column_names[0];
  }
  elseif (in_array('value', $column_names)) {
    $default_column = 'value';
  }

  // If the field has a "value" column, we probably need that one.
  $options['click_sort_column'] = [
    'default' => $default_column,
  ];
  if (isset($this->definition['default_formatter'])) {
    $options['type'] = [
      'default' => $this->definition['default_formatter'],
    ];
  }
  elseif (isset($field_type['default_formatter'])) {
    $options['type'] = [
      'default' => $field_type['default_formatter'],
    ];
  }
  else {
    $options['type'] = [
      'default' => '',
    ];
  }
  $options['settings'] = [
    'default' => isset($this->definition['default_formatter_settings']) ? $this->definition['default_formatter_settings'] : [],
  ];
  $options['group_column'] = [
    'default' => $default_column,
  ];
  $options['group_columns'] = [
    'default' => [],
  ];

  // Options used for multiple value fields.
  $options['group_rows'] = [
    'default' => TRUE,
  ];

  // If we know the exact number of allowed values, then that can be
  // the default. Otherwise, default to 'all'.
  $options['delta_limit'] = [
    'default' => $field_storage_definition
      ->getCardinality() > 1 ? $field_storage_definition
      ->getCardinality() : 0,
  ];
  $options['delta_offset'] = [
    'default' => 0,
  ];
  $options['delta_reversed'] = [
    'default' => FALSE,
  ];
  $options['delta_first_last'] = [
    'default' => FALSE,
  ];
  $options['multi_type'] = [
    'default' => 'separator',
  ];
  $options['separator'] = [
    'default' => ', ',
  ];
  $options['field_api_classes'] = [
    'default' => FALSE,
  ];
  return $options;
}