You are here

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

Same name and namespace in other branches
  1. 8 src/SchemaMetatagManager.php \Drupal\schema_metatag\SchemaMetatagManager::serialize()

Wrapper for serialize to prevent errors.

Parameters

mixed $value: The values to serialize.

Return value

string The serialized value.

Overrides SchemaMetatagManagerInterface::serialize

2 calls to SchemaMetatagManager::serialize()
SchemaMetatagManagerTest::testSerialize in tests/src/Unit/SchemaMetatagManagerTest.php
@covers ::serialize @dataProvider arrayData
schema_metatag_update_8107 in ./schema_metatag.install
Update the schema_product_brand tag.

File

src/SchemaMetatagManager.php, line 186

Class

SchemaMetatagManager
The SchemaMetatag Manager.

Namespace

Drupal\schema_metatag

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;
}