You are here

function simplenews_issue_handler_field_add in Simplenews 7.2

Add a field for the recipient handler choice.

Parameters

$type A node type object:

Related topics

2 calls to simplenews_issue_handler_field_add()
simplenews_issue_fields_add in ./simplenews.module
Add fields for newsletter, status and sent count to a note type.
simplenews_update_7206 in ./simplenews.install
Add recipient handler and handler settings field to issue content types.

File

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

Code

function simplenews_issue_handler_field_add($type) {
  $field_name = variable_get('simplenews_handler_field', 'simplenews_handler');
  $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' => 'list_text',
      'cardinality' => 1,
      'entity_types' => array(
        'node',
      ),
      'translatable' => FALSE,
      'settings' => array(
        'allowed_values_function' => 'simplenews_handler_field_allowed_values',
      ),
    );
    $field = field_create_field($field);
  }
  if (empty($instance)) {

    // We set the default value to simplenews_subscription
    $instance = array(
      'label' => t('Recipient Handler'),
      'field_name' => $field_name,
      'bundle' => $type->type,
      'entity_type' => 'node',
      'required' => TRUE,
      'default_value' => array(
        array(
          'value' => 'simplenews_subscription',
        ),
      ),
      'widget' => array(
        'type' => 'options_select',
      ),
      'display' => array(
        'default' => array(
          'label' => 'hidden',
          'type' => 'hidden',
        ),
      ),
    );
    field_create_instance($instance);
  }
}