You are here

function yashare_field_extra_fields in Yandex.Share 7.2

Same name and namespace in other branches
  1. 7 yashare.module \yashare_field_extra_fields()

Implements hook_field_extra_fields().

3 calls to yashare_field_extra_fields()
yashare_form_field_ui_display_overview_form_alter in ./yashare.module
Implements hook_form_FORM_ID_alter().
_yashare_field_formatter_settings_form in ./yashare.module
Pseudo hook_field_formatter_settings_form().
_yashare_field_formatter_settings_summary in ./yashare.module
Pseudo hook_field_formatter_settings_summary().

File

./yashare.module, line 79

Code

function yashare_field_extra_fields($get_defaults = FALSE) {
  $defaults = array(
    'label' => t('Yandex.Share'),
    'description' => t('Yandex.Share widget.'),
    'weight' => 100,
    'settings' => array(
      'image_field' => 'field_image',
      'image_style' => 'thumbnail',
      'description' => '',
    ),
  );
  if ($get_defaults) {
    return array(
      'extra_fields' => array(
        'display' => array(
          'yashare' => $defaults,
        ),
      ),
    );
  }
  $extra = array();
  foreach (entity_get_info() as $entity_type => $entity_info) {
    foreach (array_keys($entity_info['bundles']) as $bundle) {
      $extra[$entity_type][$bundle]['display']['yashare'] = $defaults;

      // Hide it by default (if there is no info about our extra field in field bundle settings).
      $field_bundle_setting = field_bundle_settings($entity_type, $bundle);
      if (empty($field_bundle_setting['extra_fields']['display']['yashare'])) {

        // Prepare all entity type view modes.
        $view_modes = array_keys($entity_info['view modes']);
        if (!in_array('default', $view_modes)) {
          $view_modes[] = 'default';
        }
        foreach ($view_modes as $view_mode) {
          $field_bundle_setting['extra_fields']['display']['yashare'][$view_mode] = array(
            'visible' => FALSE,
            'weight' => $defaults['weight'],
          );
        }
        field_bundle_settings($entity_type, $bundle, $field_bundle_setting);
      }
    }
  }
  return $extra;
}