You are here

function _file_entity_create_alt_title_fields in File Entity (fieldable files) 7.3

Same name and namespace in other branches
  1. 7.2 file_entity.install \_file_entity_create_alt_title_fields()

Function to create the title and alt text fields and instances.

2 calls to _file_entity_create_alt_title_fields()
file_entity_install in ./file_entity.install
Implements hook_install().
file_entity_update_7204 in ./file_entity.install
Add title and alt text to image file types.

File

./file_entity.install, line 563
Install, update and uninstall functions for the file_entity module.

Code

function _file_entity_create_alt_title_fields() {
  $t = get_t();

  // Create the alt text field and instance.
  // Define the alt text field.
  $alt_text_field = array(
    'active' => '1',
    'cardinality' => '1',
    'deleted' => '0',
    'entity_types' => array(),
    'field_name' => 'field_file_image_alt_text',
    'foreign keys' => array(
      'format' => array(
        'columns' => array(
          'format' => 'format',
        ),
        'table' => 'filter_format',
      ),
    ),
    'indexes' => array(
      'format' => array(
        0 => 'format',
      ),
    ),
    'module' => 'text',
    'settings' => array(
      'max_length' => '255',
    ),
    'translatable' => '0',
    'type' => 'text',
  );

  // As long as the alt text field doesn't already exist create it.
  if (!field_info_field($alt_text_field['field_name'])) {
    field_create_field($alt_text_field);
  }

  // Define the alt text instance.
  $alt_text_instance = array(
    'bundle' => 'image',
    'default_value' => NULL,
    'deleted' => '0',
    'description' => $t('Alternative text is used by screen readers, search engines, and when the image cannot be loaded. By adding alt text you improve accessibility and search engine optimization.'),
    'display' => array(
      'default' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
      'full' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
      'preview' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
      'teaser' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
    ),
    'entity_type' => 'file',
    'field_name' => 'field_file_image_alt_text',
    'label' => 'Alt Text',
    'required' => 0,
    'settings' => array(
      'text_processing' => '0',
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'active' => 1,
      'module' => 'text',
      'settings' => array(
        'size' => '60',
      ),
      'type' => 'text_textfield',
      'weight' => '-4',
    ),
  );

  // For sites that updated from Media 1.x, continue to provide these deprecated
  // view modes.
  // @see http://drupal.org/node/1051090
  if (variable_get('media__show_deprecated_view_modes')) {
    $alt_text_instance['display'] += array(
      'media_link' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
      'media_original' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
    );
  }

  // As long as the alt text instance doesn't already exist create it.
  if (!field_info_instance($alt_text_instance['entity_type'], $alt_text_instance['field_name'], $alt_text_instance['bundle'])) {
    field_create_instance($alt_text_instance);
  }

  // Create the title text field and instance.
  // Define the title text field.
  $title_text_field = array(
    'active' => '1',
    'cardinality' => '1',
    'deleted' => '0',
    'entity_types' => array(),
    'field_name' => 'field_file_image_title_text',
    'foreign keys' => array(
      'format' => array(
        'columns' => array(
          'format' => 'format',
        ),
        'table' => 'filter_format',
      ),
    ),
    'indexes' => array(
      'format' => array(
        0 => 'format',
      ),
    ),
    'module' => 'text',
    'settings' => array(
      'max_length' => '255',
    ),
    'translatable' => '0',
    'type' => 'text',
  );

  // As long as the title text field doesn't exist create it.
  if (!field_info_field($title_text_field['field_name'])) {
    field_create_field($title_text_field);
  }

  // Define the title text instance.
  $title_text_instance = array(
    'bundle' => 'image',
    'default_value' => NULL,
    'deleted' => '0',
    'description' => $t('Title text is used in the tool tip when a user hovers their mouse over the image. Adding title text makes it easier to understand the context of an image and improves usability.'),
    'display' => array(
      'default' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 1,
      ),
      'full' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
      'preview' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
      'teaser' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
    ),
    'entity_type' => 'file',
    'field_name' => 'field_file_image_title_text',
    'label' => 'Title Text',
    'required' => 0,
    'settings' => array(
      'text_processing' => '0',
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'active' => 1,
      'module' => 'text',
      'settings' => array(
        'size' => '60',
      ),
      'type' => 'text_textfield',
      'weight' => '-3',
    ),
  );

  // For sites that updated from Media 1.x, continue to provide these deprecated
  // view modes.
  // @see http://drupal.org/node/1051090
  if (variable_get('media__show_deprecated_view_modes')) {
    $title_text_instance['display'] += array(
      'media_link' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
      'media_original' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
    );
  }

  // As long as the title text instance doesn't already exist create it.
  if (!field_info_instance($title_text_instance['entity_type'], $title_text_instance['field_name'], $title_text_instance['bundle'])) {
    field_create_instance($title_text_instance);
  }
}