You are here

function oa_related_paragraphs_field_allowed_values in Open Atrium Related Content 7.2

Helper function to define allowed values for fields on a paragraph entity used to control the layout.

This function is used in place of adding allowed values for those fields in the UI.

Parameters

array $field: The field the values will be applied to.

array $instance: The field instance.

string $entity_type: The machine name of the paragraph entity.

object $entity: The paragraphs item entity.

bool $cacheable:

Return value

array

1 string reference to 'oa_related_paragraphs_field_allowed_values'
oa_related_field_default_field_bases in ./oa_related.features.field_base.inc
Implements hook_field_default_field_bases().

File

./oa_related.module, line 608

Code

function oa_related_paragraphs_field_allowed_values($field, $instance, $entity_type, $entity, $cacheable) {
  $cache = cache_get(__FUNCTION__ . ':' . $instance['field_name'] . ':' . $instance['bundle'], 'cache_field');
  if (!$cache) {

    // Get information from all modules about this field. The field name does matter, there could be two fields on the
    // same bundle that allow different options.
    $info = oa_related_get_paragraph_field_info();
    $values = array();
    foreach ($info as $field_name => $bundle) {
      if ($field_name == $instance['field_name']) {
        foreach ($bundle as $name => $data) {
          $values = $data['allowed values'];

          // Allow any module to alter these options.
          drupal_alter('oa_related_' . $field_name . '_' . $name . '_values', $values);
        }
      }
    }
    cache_set(__FUNCTION__ . ':' . $instance['field_name'] . ':' . $instance['bundle'], $values, 'cache_field');
    return $values;
  }
  else {
    if (!empty($cache->data)) {
      return $cache->data;
    }
  }
}