You are here

function _oa_related_enable_related in Open Atrium Related Content 7.2

Helper function to enable or disable related content for a given node type. NOTE: This determines if the content type is available via the Related Content Paragraph type It is *not* related to whether oa_related field is added to the content type. See the oa_related_features_template_info() for that. This just modifies the target_bundles for the oa_related_content entityreference.

Parameters

string $type content type (bundle):

bool $value:

2 calls to _oa_related_enable_related()
oa_related_node_type_update in ./oa_related.module
Implements hook_node_type_update().
oa_related_panels_display_save in ./oa_related.module
Implements hook_panels_display_save().

File

./oa_related.module, line 126

Code

function _oa_related_enable_related($type, $value = TRUE) {
  $field = field_info_field('field_oa_related_content');

  // Installing site, field doesn't exist, exit out.
  if (!$field) {
    return;
  }

  // If it isn't a group content type then exit
  if (!og_is_group_content_type('node', $type)) {
    return;
  }
  if ($value) {
    $do_update = empty($field['settings']['handler_settings']['target_bundles'][$type]);
    $field['settings']['handler_settings']['target_bundles'][$type] = $type;
  }
  else {
    $do_update = !empty($field['settings']['handler_settings']['target_bundles'][$type]);
    unset($field['settings']['handler_settings']['target_bundles'][$type]);
  }
  if ($do_update) {
    field_update_field($field);
    $message = $value ? t('Enabled !type for related content references.', array(
      '!type' => $type,
    )) : t('Disabled !type for related content references.', array(
      '!type' => $type,
    ));
    if (variable_get('install_task') == 'done') {
      drupal_set_message($message);
    }
  }
}