public function MetadataFactory::getMetadataFor

Implements MetadataFactoryInterface::getMetadataFor().

Parameters

\Drupal\Core\TypedData\TypedDataInterface $typed_data: Some typed data object containing the value to validate.

$name: (optional) The name of the property to get metadata for. Leave empty, if the data is the root of the typed data tree.

Overrides MetadataFactoryInterface::getMetadataFor

File

drupal/core/lib/Drupal/Core/TypedData/Validation/MetadataFactory.php, line 29
Contains \Drupal\Core\TypedData\Validation\MetadataFactory.

Class

MetadataFactory
Typed data implementation of the validator MetadataFactoryInterface.

Namespace

Drupal\Core\TypedData\Validation

Code

public function getMetadataFor($typed_data, $name = '') {
  if (!$typed_data instanceof TypedDataInterface) {
    throw new \InvalidArgumentException('The passed value must be a typed data object.');
  }
  $is_container = $typed_data instanceof ComplexDataInterface || $typed_data instanceof ListInterface;
  $class = '\\Drupal\\Core\\TypedData\\Validation\\' . ($is_container ? 'PropertyContainerMetadata' : 'Metadata');
  return new $class($typed_data, $name, $this);
}