You are here

public function OgVocab::getMockedField in OG Vocabulary 7

Helper function to return the field and instance settings mocked.

Mocking the fields is done be getting the original field values, and overidding them based on the "settings" key of the OG-vocab entity.

Return value

Array with the field and instance arrays.

1 call to OgVocab::getMockedField()
OgVocab::getFormElement in includes/og_vocab.og_vocab.inc
Return form element.

File

includes/og_vocab.og_vocab.inc, line 134
A class used for messages.

Class

OgVocab
@file A class used for messages.

Code

public function getMockedField() {
  $vocabulary = taxonomy_vocabulary_load($this->vid);
  $field = field_info_field($this->field_name);
  $instance = field_info_instance($this->entity_type, $this->field_name, $this->bundle);
  $mocked_field = $mocked_instance = array();
  $widget_type = $this->settings['widget_type'];
  $mocked_instance['widget']['type'] = $widget_type;

  // Set the widget's module.
  $widget_info = field_info_widget_types($widget_type);
  $mocked_instance['widget']['module'] = $widget_info['module'];
  $mocked_instance['widget']['settings'] = drupal_array_merge_deep($widget_info['settings'], $instance['widget']['settings']);

  // Set widget's auto complete path if needed.
  if (in_array($this->settings['widget_type'], array(
    'entityreference_autocomplete',
    'entityreference_autocomplete_tags',
  ))) {
    $mocked_instance['widget']['settings']['autocomplete_path'] = 'og-vocab/autocomplete/single/%entity_object';
  }

  // Set required.
  $mocked_instance['required'] = $this->settings['required'];
  $instance['label'] = check_plain($vocabulary->name);

  // Set cardinality.
  $mocked_field['cardinality'] = $this->settings['cardinality'];

  // Restrict the mocked field to the target bundle.
  $mocked_field['settings']['handler_settings']['target_bundles'][$vocabulary->machine_name] = $vocabulary->machine_name;
  $field = drupal_array_merge_deep($field, $mocked_field);
  $instance = drupal_array_merge_deep($instance, $mocked_instance);
  return array(
    'field' => $field,
    'instance' => $instance,
  );
}