Skip to content

Instantly share code, notes, and snippets.

@alexpott
Created July 11, 2014 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpott/644c1146af8afac8bd76 to your computer and use it in GitHub Desktop.
Save alexpott/644c1146af8afac8bd76 to your computer and use it in GitHub Desktop.
diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php
index 65ce0c2..4041a32 100644
--- a/core/lib/Drupal/Core/Entity/EntityManager.php
+++ b/core/lib/Drupal/Core/Entity/EntityManager.php
@@ -921,15 +921,16 @@ public function loadEntityByUuid($entity_type_id, $uuid) {
/**
* {@inheritdoc}
*/
- public function getBundleFieldDefinition($entity_type, $bundle, $field_name) {
- $definitions = $this->getFieldDefinitions($entity_type, $bundle);
- if (!isset($definitions[$field_name])) {
- throw new FieldException(String::format('Field %name or entity type %type does not exist', array('%name' => $field_name, '%type' => $entity_type)));
+ public function getBundleFieldDefinition($entity_type_id, $bundle, $field_name) {
+ // Ensure that $this->fieldDefinitions is set.
+ $this->getFieldDefinitions($entity_type_id, $bundle);
+ if (!isset($this->fieldDefinitions[$entity_type_id][$bundle][$field_name])) {
+ throw new FieldException(String::format('Field %name or entity type %type does not exist', array('%name' => $field_name, '%type' => $entity_type_id)));
}
- if ($definitions[$field_name] instanceof BundleFieldDefinitionInterface) {
- return $definitions[$field_name];
+ if (!$this->fieldDefinitions[$entity_type_id][$bundle] instanceof BundleFieldDefinitionInterface) {
+ $this->fieldDefinitions[$entity_type_id][$bundle] = BundleFieldDefinition::createFromFieldDefinition($this->fieldDefinitions[$entity_type_id][$bundle][$field_name], $bundle);
}
- return BundleFieldDefinition::createFromFieldDefinition($definitions[$field_name], $bundle);
+ return $this->fieldDefinitions[$entity_type_id][$bundle];
}
}
diff --git a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php
index 431983a..03c36d7 100644
--- a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php
+++ b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php
@@ -377,7 +377,7 @@ public function loadEntityByUuid($entity_type_id, $uuid);
/**
* Gets the bundle field definition.
*
- * @param string $entity_type
+ * @param string $entity_type_id
* The entity type ID. Only entity types that implement
* \Drupal\Core\Entity\ContentEntityInterface are supported.
* @param string $bundle
@@ -394,6 +394,6 @@ public function loadEntityByUuid($entity_type_id, $uuid);
* Exception thrown if called with an non existent field name or entity
* type.
*/
- public function getBundleFieldDefinition($entity_type, $bundle, $field_name);
+ public function getBundleFieldDefinition($entity_type_id, $bundle, $field_name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment