You are here

function _cer_entity_settings_create_instance in Corresponding Entity References 7.3

Instantiates the cer_settings and cer_store_settings fields at the head of the given chain, if they aren't already there.

1 call to _cer_entity_settings_create_instance()
cer_entity_settings_cer_update in extensions/cer_entity_settings/cer_entity_settings.module
Implements hook_cer_update().

File

extensions/cer_entity_settings/cer_entity_settings.module, line 121

Code

function _cer_entity_settings_create_instance(FieldChain $chain) {
  $field = $chain
    ->current();
  $instance = field_info_instance($field->entityType, 'cer_settings', $field->bundle);
  if (empty($instance)) {
    $instance = array(
      'bundle' => $field->bundle,
      'default_value' => NULL,
      'deleted' => 0,
      'description' => '',
      'display' => array(
        'default' => array(
          'label' => 'above',
          'module' => 'entityreference',
          'settings' => array(
            'link' => FALSE,
          ),
          'type' => 'entityreference_label',
          'weight' => 1,
        ),
      ),
      'entity_type' => $field->entityType,
      'field_name' => 'cer_settings',
      'label' => t('Synchronize this @entity_type with...', array(
        '@entity_type' => $field->entityTypeLabel,
      )),
      'required' => 0,
      'settings' => array(),
      'widget' => array(
        'active' => 1,
        'module' => 'options',
        'settings' => array(
          'match_operator' => 'CONTAINS',
          'path' => '',
          'size' => 60,
        ),
        'type' => 'options_buttons',
        'weight' => 1,
      ),
    );
    field_create_instance($instance);
  }
  $instance = field_info_instance($field->entityType, 'cer_store_settings', $field->bundle);
  if (empty($instance)) {
    $instance = array(
      'bundle' => $field->bundle,
      'default_value' => array(
        0 => array(
          'value' => 1,
        ),
      ),
      'deleted' => 0,
      'description' => '',
      'display' => array(
        'default' => array(
          'label' => 'above',
          'module' => 'list',
          'settings' => array(),
          'type' => 'list_default',
          'weight' => 2,
        ),
        'teaser' => array(
          'label' => 'above',
          'settings' => array(),
          'type' => 'hidden',
          'weight' => 0,
        ),
      ),
      'entity_type' => $field->entityType,
      'field_name' => 'cer_store_settings',
      'label' => t('Remember these settings'),
      'required' => 0,
      'settings' => array(),
      'widget' => array(
        'active' => 1,
        'module' => 'options',
        'settings' => array(
          'display_label' => 1,
        ),
        'type' => 'options_onoff',
        'weight' => 2,
      ),
    );
    field_create_instance($instance);
  }
}