X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FPlugin%2FContext%2FEntityContext.php;fp=web%2Fcore%2Flib%2FDrupal%2FCore%2FPlugin%2FContext%2FEntityContext.php;h=131360df26d880f98bf441a284bc7765fadffb08;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/lib/Drupal/Core/Plugin/Context/EntityContext.php b/web/core/lib/Drupal/Core/Plugin/Context/EntityContext.php new file mode 100644 index 000000000..131360df2 --- /dev/null +++ b/web/core/lib/Drupal/Core/Plugin/Context/EntityContext.php @@ -0,0 +1,62 @@ +getDefinition($entity_type_id); + return static::fromEntityType($entity_type, $label); + } + + /** + * Gets a context from an entity type. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * Entity type from which a definition will be derived. + * @param string $label + * (optional) The label of the context. + * + * @return static + */ + public static function fromEntityType(EntityTypeInterface $entity_type, $label = NULL) { + $definition = EntityContextDefinition::fromEntityType($entity_type); + if ($label) { + $definition->setLabel($label); + } + return new static($definition); + } + + /** + * Gets a context object from an entity. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * Entity that provides a context. + * @param string $label + * (optional) The label of the context. + * + * @return \Drupal\Core\Plugin\Context\EntityContext + */ + public static function fromEntity(EntityInterface $entity, $label = NULL) { + $context = static::fromEntityType($entity->getEntityType(), $label); + $context->setContextValue($entity); + return $context; + } + +}