You are here

public function WrapperTarget::valuesAreEmpty in Feeds Paragraphs 8

Checks whether the values are empty.

Parameters

array $values: The values

Return value

bool True if the values are empty.

1 call to WrapperTarget::valuesAreEmpty()
WrapperTarget::setTarget in src/Feeds/Target/WrapperTarget.php
Sets the values on an object.

File

src/Feeds/Target/WrapperTarget.php, line 163

Class

WrapperTarget
Defines a wrapper target around a paragraph bundle's target field.

Namespace

Drupal\feeds_para_mapper\Feeds\Target

Code

public function valuesAreEmpty(array $values) {
  $properties = $this->targetDefinition
    ->getProperties();
  $emptyValues = 0;
  foreach ($values as $value) {
    $currentProperties = array_keys($value);
    $emptyProps = [];
    foreach ($properties as $property) {
      foreach ($currentProperties as $currentProperty) {
        if ($currentProperty === $property) {
          if (is_array($value[$currentProperty])) {
            $emptySubValues = 0;
            foreach ($value[$currentProperty] as $subValue) {
              if (!strlen($subValue)) {
                $emptySubValues++;
              }
            }
            if ($emptySubValues === count($value[$currentProperty])) {
              $emptyProps[] = $currentProperty;
            }
          }
          else {
            if (!strlen($value[$currentProperty])) {
              $emptyProps[] = $currentProperty;
            }
          }
        }
      }
    }
    if (count($emptyProps) === count($properties)) {
      $emptyValues++;
    }
  }
  return $emptyValues === count($values);
}