You are here

class FormEntityContext in Flexiform 8

Class for form entity contexts.

Hierarchy

Expanded class hierarchy of FormEntityContext

File

src/FormEntity/FormEntityContext.php, line 13

Namespace

Drupal\flexiform\FormEntity
View source
class FormEntityContext extends Context implements FormEntityContextInterface {
  use DependencySerializationTrait;

  /**
   * The entity namespace.
   *
   * @var string
   */
  protected $entityNamespace;

  /**
   * The form entity plugin.
   *
   * @var \Drupal\flexiform\FormEntity\FlexiformFormEntityInterface
   */
  protected $formEntity;

  /**
   * {@inheritdoc}
   */
  public function setEntityNamespace($namespace) {
    $this->entityNamespace = $namespace;
  }

  /**
   * {@inheritdoc}
   */
  public function getEntityNamespace() {
    return $this->entityNamespace;
  }

  /**
   * {@inheritdoc}
   */
  public function getFormEntity() {
    return $this->formEntity;
  }

  /**
   * {@inheritdoc}
   */
  public function setFormEntity(FlexiformFormEntityInterface $form_entity) {
    $this->formEntity = $form_entity;
  }

  /**
   * {@inheritdoc}
   */
  public function hasContextValue() {
    if (!$this->contextData) {
      $this
        ->getContextValue();
    }
    return parent::hasContextValue();
  }

  /**
   * {@inheritdoc}
   */
  public function getContextValue() {
    if (!$this->contextData) {
      $this
        ->setContextValue($this
        ->getFormEntity()
        ->getEntity());
    }
    return parent::getContextValue();
  }

  /**
   * Create from a form entity plugin.
   *
   * @param \Drupal\flexiform\FormEntity\FlexiformFormEntityInterface $form_entity
   *   The form entity plugin.
   * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
   *   The form entity to create from.
   *
   * @return static
   *   The generated context.
   */
  public static function createFromFlexiformFormEntity(FlexiformFormEntityInterface $form_entity, FieldableEntityInterface $entity = NULL) {
    $context_definition = new ContextDefinition('entity:' . $form_entity
      ->getEntityType(), $form_entity
      ->getLabel());
    $context_definition
      ->addConstraint('Bundle', [
      $form_entity
        ->getBundle(),
    ]);
    $context = new static($context_definition, $entity);
    $context
      ->setFormEntity($form_entity);
    return $context;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Context::$cacheabilityMetadata protected property The cacheability metadata.
Context::$contextData protected property The data associated with the context.
Context::$contextDefinition protected property The definition to which a context must conform. Overrides Context::$contextDefinition
Context::$contextValue protected property The value of the context.
Context::addCacheableDependency public function Adds a dependency on an object: merges its cacheability metadata. Overrides ContextInterface::addCacheableDependency
Context::createFromContext public static function Creates a new context with a different value. Overrides ContextInterface::createFromContext
Context::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts
Context::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
Context::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags
Context::getConstraints public function Gets a list of validation constraints. Overrides Context::getConstraints
Context::getContextData public function Gets the context value as typed data object. Overrides ContextInterface::getContextData
Context::getContextDefinition public function Gets the provided definition that the context must conform to. Overrides Context::getContextDefinition
Context::setContextValue protected function Sets the context value.
Context::validate public function Validates the set context value. Overrides Context::validate
Context::__construct public function Create a context object. Overrides Context::__construct
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormEntityContext::$entityNamespace protected property The entity namespace.
FormEntityContext::$formEntity protected property The form entity plugin.
FormEntityContext::createFromFlexiformFormEntity public static function Create from a form entity plugin.
FormEntityContext::getContextValue public function Gets the context value. Overrides Context::getContextValue
FormEntityContext::getEntityNamespace public function Get the entity namespace. Overrides FormEntityContextInterface::getEntityNamespace
FormEntityContext::getFormEntity public function Get the form entity plugin. Overrides FormEntityContextInterface::getFormEntity
FormEntityContext::hasContextValue public function Returns whether the context has a value. Overrides Context::hasContextValue
FormEntityContext::setEntityNamespace public function Set the entity namespace. Overrides FormEntityContextInterface::setEntityNamespace
FormEntityContext::setFormEntity public function
TypedDataTrait::$typedDataManager protected property The typed data manager used for creating the data types.
TypedDataTrait::getTypedDataManager public function Gets the typed data manager. 2
TypedDataTrait::setTypedDataManager public function Sets the typed data manager. 2