diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 5f7251a..678e493 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -43,45 +43,33 @@ class FieldInfo { * * @var array */ - protected $fieldsById; + protected $fieldsById = array(); /** * Mapping of field names to the ID of the corresponding non-deleted field. * * @var array */ - protected $fieldIdsByName; + protected $fieldIdsByName = array(); /** * Contents of bundles ($instance definitions and extra fields). * * @var array */ - protected $bundleInfo; + protected $bundleInfo = array(); - /** - * Constructs a FieldInfo object. - */ - function __construct() { - $this->init(); - } + const MISSING_FIELD_ID = -1; /** * Clears the "static" and persistent caches. */ public function flush() { - $this->init(); - cache('field')->deletePrefix('field_info:'); - } - - /** - * Initializes the "static" cache. - */ - protected function init() { - $this->fieldMap = array(); + $this->fieldMap = NULL; $this->fieldsById = array(); $this->fieldIdsByName = array(); $this->bundleInfo = array(); + cache('field')->deletePrefix('field_info:'); } /** @@ -93,7 +81,7 @@ class FieldInfo { */ protected function getFieldMap() { // Read from the "static" cache. - if ($this->fieldMap) { + if ($this->fieldMap !== NULL) { return $this->fieldMap; } @@ -213,7 +201,7 @@ class FieldInfo { */ public function getField($field_name) { // Read from the "static" cache. - if (isset($this->fieldIdsByName[$field_name])) { + if (isset($this->fieldIdsByName[$field_name]) || array_key_exists($field_name, $this->fieldIdsByName)) { return $this->fieldsById[$this->fieldIdsByName[$field_name]]; } @@ -230,6 +218,11 @@ class FieldInfo { return $field; } + else { + // Save in the "static" cache that this field does not exist. + $this->fieldsById[self::MISSING_FIELD_ID] = NULL; + $this->fieldIdsByName[$field_name] = self::MISSING_FIELD_ID; + } } /** @@ -245,7 +238,7 @@ class FieldInfo { */ public function getFieldById($field_id) { // Read from the "static" cache. - if (isset($this->fieldsById[$field_id])) { + if (isset($this->fieldsById[$field_id]) || array_key_exists($field_id, $this->fieldsById)) { return $this->fieldsById[$field_id]; } @@ -265,6 +258,9 @@ class FieldInfo { return $field; } + else { + $this->fieldsById[$field_id] = NULL; + } } /** @@ -285,10 +281,13 @@ class FieldInfo { */ public function getBundleInfo($entity_type, $bundle) { // Read from the "static" cache. - if (isset($this->bundleInfo[$entity_type][$bundle])) { + if (isset($this->bundleInfo[$entity_type][$bundle]) || (isset($this->bundleInfo[$entity_type]) && array_key_exists($bundle, $this->bundleInfo[$entity_type]))) { return $this->bundleInfo[$entity_type][$bundle]; } + // Make sure that the bundle info is initialized. + $this->bundleInfo[$entity_type][$bundle] = NULL; + // Read from the persistent cache. if ($cached = cache('field')->get("field_info:bundle:$entity_type:$bundle")) { $info = $cached->data;