class PropertyContainerMetadata

Typed data implementation of the validator MetadataInterface.

Hierarchy

Expanded class hierarchy of PropertyContainerMetadata

1 string reference to 'PropertyContainerMetadata'
MetadataFactory::getMetadataFor in drupal/core/lib/Drupal/Core/TypedData/Validation/MetadataFactory.php
Implements MetadataFactoryInterface::getMetadataFor().

File

drupal/core/lib/Drupal/Core/TypedData/Validation/PropertyContainerMetadata.php, line 18
Contains \Drupal\Core\TypedData\Validation\PropertyContainerMetadata.

Namespace

Drupal\Core\TypedData\Validation
View source
class PropertyContainerMetadata extends Metadata implements PropertyMetadataContainerInterface {

  /**
   * Overrides Metadata::accept().
   */
  public function accept(ValidationVisitorInterface $visitor, $typed_data, $group, $propertyPath) {

    // To let all constraints properly handle empty structures, pass on NULL
    // if the data structure is empty. That way existing NotNull or NotBlank
    // constraints work as expected.
    if ($typed_data
      ->isEmpty()) {
      $typed_data = NULL;
    }
    $visitor
      ->visit($this, $typed_data, $group, $propertyPath);
    $pathPrefix = empty($propertyPath) ? '' : $propertyPath . '.';
    if ($typed_data) {
      foreach ($typed_data as $name => $data) {
        $metadata = $this->factory
          ->getMetadataFor($data, $name);
        $metadata
          ->accept($visitor, $data, $group, $pathPrefix . $name);
      }
    }
  }

  /**
   * Implements PropertyMetadataContainerInterface::hasPropertyMetadata().
   */
  public function hasPropertyMetadata($property_name) {
    try {
      $exists = (bool) $this
        ->getPropertyMetadata($property_name);
    } catch (\LogicException $e) {
      $exists = FALSE;
    }
    return $exists;
  }

  /**
   * Implements PropertyMetadataContainerInterface::getPropertyMetadata().
   */
  public function getPropertyMetadata($property_name) {
    if ($this->typedData instanceof ListInterface) {
      return array(
        new Metadata($this->typedData[$property_name], $property_name),
      );
    }
    elseif ($this->typedData instanceof ComplexDataInterface) {
      return array(
        new Metadata($this->typedData
          ->get($property_name), $property_name),
      );
    }
    else {
      throw new \LogicException("There are no known properties.");
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Metadata::$factory protected property The metadata factory used.
Metadata::$name protected property The name of the property, or empty if this is the root.
Metadata::$typedData protected property The typed data object the metadata is about.
Metadata::findConstraints public function Implements MetadataInterface::findConstraints(). Overrides MetadataInterface::findConstraints
Metadata::getPropertyName public function Returns the name of the property. Overrides PropertyMetadataInterface::getPropertyName
Metadata::getPropertyValue public function Extracts the value of the property from the given container. Overrides PropertyMetadataInterface::getPropertyValue
Metadata::__construct public function Constructs the object.
PropertyContainerMetadata::accept public function Overrides Metadata::accept(). Overrides Metadata::accept
PropertyContainerMetadata::getPropertyMetadata public function Implements PropertyMetadataContainerInterface::getPropertyMetadata(). Overrides PropertyMetadataContainerInterface::getPropertyMetadata
PropertyContainerMetadata::hasPropertyMetadata public function Implements PropertyMetadataContainerInterface::hasPropertyMetadata(). Overrides PropertyMetadataContainerInterface::hasPropertyMetadata