You are here

function simplenews_add_term_field in Simplenews 7

Add the taxonomy term field for the newsletter category.

Parameters

$type: A node type object.

Related topics

3 calls to simplenews_add_term_field()
simplenews_node_type_insert in ./simplenews.module
Implements hook_node_type_insert().
simplenews_node_type_update in ./simplenews.module
Implements hook_node_type_update().
_simplenews_install_nodetype in ./simplenews.install
Create simplenews node type.

File

./simplenews.module, line 599
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_add_term_field($type) {
  $field_name = variable_get('simplenews_category_field', 'field_simplenews_term');
  $field = field_info_field($field_name);
  $instance = field_info_instance('node', $field_name, $type->type);
  if (empty($field)) {
    $field = array(
      'field_name' => $field_name,
      'type' => 'taxonomy_term_reference',
      'cardinality' => 1,
      //'entity_types' => array(),
      'translatable' => TRUE,
      'settings' => array(
        'allowed_values' => array(
          array(
            'parent' => 0,
            'vocabulary' => 'newsletter',
          ),
        ),
      ),
    );
    $field = field_create_field($field);
  }
  if (empty($instance)) {
    $instance = array(
      'label' => t('Newsletter category'),
      'field_name' => $field_name,
      'bundle' => $type->type,
      'entity_type' => 'node',
      'required' => TRUE,
      'widget' => array(
        'type' => 'options_buttons',
      ),
      //'settings' => array(),
      'display' => array(
        'default' => array(
          'label' => 'hidden',
          'type' => 'taxonomy_term_reference_link',
        ),
        'teaser' => array(
          'label' => 'hidden',
          'type' => 'hidden',
        ),
        'email_plain' => array(
          'label' => 'hidden',
          'type' => 'hidden',
        ),
        'email_html' => array(
          'label' => 'hidden',
          'type' => 'hidden',
        ),
        'email_textalt' => array(
          'label' => 'hidden',
          'type' => 'hidden',
        ),
      ),
    );
    field_create_instance($instance);
  }
}