You are here

function Field::fakeFieldInstance in Views (for Drupal 7) 8.3

Provides a fake field instance.

Parameters

string $formatter: The machine name of the formatter to use.

array $formatter_settings: An associative array of settings for the formatter.

Return value

array An associative array of instance date for the fake field.

See also

field_info_instance()

1 call to Field::fakeFieldInstance()
Field::buildOptionsForm in lib/Views/field/Plugin/views/field/Field.php
Default options form that provides the label widget that all fields should have.

File

lib/Views/field/Plugin/views/field/Field.php, line 411
Definition of Views\field\Plugin\views\field\Field.

Class

Field
A field that displays fieldapi fields.

Namespace

Views\field\Plugin\views\field

Code

function fakeFieldInstance($formatter, $formatter_settings) {
  $field_name = $this->definition['field_name'];
  $field = field_read_field($field_name);
  $field_type = field_info_field_types($field['type']);
  return array(
    // Build a fake entity type and bundle.
    'field_name' => $field_name,
    'entity_type' => 'views_fake',
    'bundle' => 'views_fake',
    // Use the default field settings for settings and widget.
    'settings' => field_info_instance_settings($field['type']),
    'widget' => array(
      'type' => $field_type['default_widget'],
      'settings' => array(),
    ),
    // Build a dummy display mode.
    'display' => array(
      '_custom' => array(
        'type' => $formatter,
        'settings' => $formatter_settings,
      ),
    ),
    // Set the other fields to their default values.
    // @see _field_write_instance().
    'required' => FALSE,
    'label' => $field_name,
    'description' => '',
    'deleted' => 0,
  );
}