You are here

public static function SchemaMetatagManager::serialize in Schema.org Metatag 7

Wrapper for serialize to prevent errors.

Parameters

array $value: The array to serialize.

Return value

string The serialized value. Wrapper for serialize to prevent errors.

Overrides SchemaMetatagManagerInterface::serialize

1 call to SchemaMetatagManager::serialize()
schema_metatag_element_validate in ./schema_metatag.module
Validation callback for a schema_metatag element to serialize nested arrays.

File

src/SchemaMetatagManager.php, line 197
A generic substitution for Drupal 8 Random utility.

Class

SchemaMetatagManager
Class SchemaMetatagManager.

Code

public static function serialize($value) {

  // Make sure the same value isn't serialized more than once if this is
  // called multiple times.
  if (is_array($value)) {

    // Don't serialize an empty array.
    // Otherwise Metatag won't know the field is empty.
    $trimmed = self::arrayTrim($value);
    if (empty($trimmed)) {
      return '';
    }
    else {
      $value = serialize($trimmed);
    }
  }
  return $value;
}