1 field.block.inc protected FieldBlock::createPseudoInstance($formatter_name, $formatter_settings)

Create a field instance and display that uses custom formatter settings.

This helper function provides a fake field instance with a display called "_custom". Formatter callbacks require a full instance, but in the case of the field blocks, there isn't full instance because the bundle isn't yet known.

Parameters

$formatter_name: The formatter to be used with this instance.

$formatter_settings: The settings for the given formatter.

Return value

array: An array matching a field instance as provided by field_info_instance().

File

core/modules/field/field.block.inc, line 314

Class

FieldBlock
FieldBlock extends Block

Code

protected function createPseudoInstance($formatter_name, $formatter_settings) {
  list($entity_type, $field_name) = explode('-', $this->childDelta);
  $field = field_info_field($field_name);
  $field_type = field_info_field_types($field['type']);

  $instance = array(
    // Build a fake entity type and bundle.
    'field_name' => $field_name,
    'entity_type' => 'block',
    'bundle' => 'block',

    // 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_name,
        'settings' => $formatter_settings,
      ),
    ),

    // Set the other fields to their default values.
    // @see _field_write_instance().
    'required' => FALSE,
    'label' => $field['field_name'],
    'description' => '',
    'deleted' => 0,
  );

  return $instance;
}