You are here

function classy_paragraphs_get_classes in Classy paragraphs 7

Get class names from paragraph item.

Parameters

ParagraphsItemEntity $item:

Return value

string[]

1 call to classy_paragraphs_get_classes()
classy_paragraphs_preprocess_entity in ./classy_paragraphs.module
Implements template_preprocess_entity()

File

./classy_paragraphs.module, line 52
Main module file for Classy Paragraphs.

Code

function classy_paragraphs_get_classes(ParagraphsItemEntity $item) {
  $classes = array();
  $instances = field_info_instances(CLASSY_PARAGRAPHS_ENTITY_TYPE, $item->bundle);
  foreach ($instances as $instance) {
    $field_name = $instance['field_name'];
    $field = field_info_field($field_name);
    if ($field['type'] == CLASSY_PARAGRAPHS_FIELD_TYPE_LIST) {

      // Determine the list of languages to iterate on.
      $languages = field_available_languages(CLASSY_PARAGRAPHS_ENTITY_TYPE, $field);
      foreach ($languages as $langcode) {
        if (!empty($item->{$field_name}[$langcode])) {
          foreach ($item->{$field_name}[$langcode] as $field_item) {
            $classes[] = $field_item['value'];
          }
        }
      }
    }
  }
  return $classes;
}