diff --git a/file_entity.install b/file_entity.install index 305b80b..014ad4a 100644 --- a/file_entity.install +++ b/file_entity.install @@ -151,6 +151,9 @@ function file_entity_install() { foreach ($roles as $rid => $role) { user_role_grant_permissions($rid, array('view file')); } + + // Create the title and alt text fields + _file_entity_create_alt_title_fields(); } /** @@ -317,3 +320,225 @@ function file_entity_update_7200() { ); db_create_table('image_dimensions', $schema['image_dimensions']); } + +/** + * Add title and alt text to image file types. + */ +function file_entity_update_7201() { + _file_entity_create_alt_title_fields(); +} + +/** + * Function to create the title and alt text fields + * and instances. + */ +function _file_entity_create_alt_title_fields() { + // 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' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 0, + ), + 'media_large' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'media_link' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'media_original' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'media_preview' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'media_small' => 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', + ), + ); + + // 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' => 'Title text attribute', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 1, + ), + 'media_large' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'media_link' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'media_original' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'media_preview' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'media_small' => 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', + ), + ); + + // 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); + } + +}