You are here

function _media_gallery_ensure_field_tags in Media Gallery 7

Same name and namespace in other branches
  1. 7.2 media_gallery.install \_media_gallery_ensure_field_tags()

Make sure the field_tags field exists and is of the right type.

1 call to _media_gallery_ensure_field_tags()
media_gallery_install in ./media_gallery.install
Implements hook_install().

File

./media_gallery.install, line 816
Install file for media_gallery. Includes field and instance definitions.

Code

function _media_gallery_ensure_field_tags() {

  // Make sure the 'tags' vocabulary exists.
  $vocabulary = taxonomy_vocabulary_machine_name_load('tags');
  if (!$vocabulary) {
    $description = st('Use tags to group articles on similar topics into categories.');
    $help = st('Enter a comma-separated list of words to describe your content.');
    $vocabulary = (object) array(
      'name' => 'Tags',
      'description' => $description,
      'machine_name' => 'tags',
      'help' => $help,
    );
    taxonomy_vocabulary_save($vocabulary);
  }
  $field = array(
    'field_name' => 'field_tags',
    'type' => 'taxonomy_term_reference',
    // Set cardinality to unlimited for tagging.
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $vocabulary->machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  _media_gallery_ensure_field($field);
}