You are here

function paragraphs_item_is_empty in Paragraphs 7

Determines whether a paragraphs field item is empty.

1 call to paragraphs_item_is_empty()
paragraphs_field_is_empty in ./paragraphs.module
Implements hook_field_is_empty().

File

./paragraphs.module, line 885
Paragraphs hooks and common functions.

Code

function paragraphs_item_is_empty(ParagraphsItemEntity $item) {
  $instances = field_info_instances('paragraphs_item', $item->bundle);
  $is_empty = TRUE;
  foreach ($instances as $instance) {
    $field_name = $instance['field_name'];
    $field = field_info_field($field_name);

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

        // If at least one paragraph is not empty; the
        // paragraph item is not empty.
        foreach ($item->{$field_name}[$langcode] as $field_item) {
          if (!module_invoke($field['module'], 'field_is_empty', $field_item, $field)) {
            $is_empty = FALSE;
          }
        }
      }
    }
  }

  // Allow other modules a chance to alter the value before returning.
  drupal_alter('paragraphs_is_empty', $is_empty, $item);
  return $is_empty;
}