Skip to content

Instantly share code, notes, and snippets.

@damiankloip
Last active January 2, 2016 02:19
Show Gist options
  • Select an option

  • Save damiankloip/8236689 to your computer and use it in GitHub Desktop.

Select an option

Save damiankloip/8236689 to your computer and use it in GitHub Desktop.
diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php
index 1d86e02..2ada67b 100644
--- a/core/lib/Drupal/Core/Entity/EntityType.php
+++ b/core/lib/Drupal/Core/Entity/EntityType.php
@@ -205,23 +205,21 @@ class EntityType implements EntityTypeInterface {
* An array of values from the annotation.
*/
public function __construct($definition) {
- foreach ($definition as $property => $value) {
- $this->{$property} = $value;
- }
+ $this->definition = $definition;
}
/**
* {@inheritdoc}
*/
- public function get($property) {
- return isset($this->{$property}) ? $this->{$property} : NULL;
+ public function get($property, $default = NULL) {
+ return isset($this->definition[$property]) ? $this->definition[$property] : $default;
}
/**
* {@inheritdoc}
*/
public function set($property, $value) {
- $this->{$property} = $value;
+ $this->definition[$property] = $value;
return $this;
}
@@ -229,28 +227,28 @@ public function set($property, $value) {
* {@inheritdoc}
*/
public function isStaticallyCacheable() {
- return isset($this->static_cache) ? $this->static_cache: TRUE;
+ return $this->get('static_cache', TRUE);
}
/**
* {@inheritdoc}
*/
public function isRenderCacheable() {
- return isset($this->render_cache) ? $this->render_cache: TRUE;
+ return $this->get('render_cache', TRUE);
}
/**
* {@inheritdoc}
*/
public function isFieldDataCacheable() {
- return isset($this->field_cache) ? $this->field_cache: TRUE;
+ return $this->get('field_cache', TRUE);
}
/**
* {@inheritdoc}
*/
public function getKeys() {
- return $this->entity_keys + array('revision' => '', 'bundle' => '');
+ return $this->get('entity_keys', array()) + array('revision' => '', 'bundle' => '');
}
/**
@@ -273,28 +271,28 @@ public function hasKey($key) {
* {@inheritdoc}
*/
public function id() {
- return $this->id;
+ return $this->get('id');
}
/**
* {@inheritdoc}
*/
public function getProvider() {
- return $this->provider;
+ return $this->get('provider');
}
/**
* {@inheritdoc}
*/
public function getClass() {
- return $this->class;
+ return $this->get('class');
}
/**
* {@inheritdoc}
*/
public function setClass($class) {
- $this->class = $class;
+ $this->set('class', $class);
return $this;
}
@@ -309,7 +307,7 @@ public function isSubclassOf($class) {
* {@inheritdoc}
*/
public function getControllers() {
- return $this->controllers + array(
+ return $this->get('controllers', array()) + array(
'access' => 'Drupal\Core\Entity\EntityAccessController',
);
}
@@ -326,7 +324,9 @@ public function getController($controller_type) {
* {@inheritdoc}
*/
public function setController($controller_type, $value) {
- $this->controllers[$controller_type] = $value;
+ $controllers = $this->getControllers();
+ $controllers[$controller_type] = $value;
+ $this->set('controllers', $controllers);
return $this;
}
@@ -342,7 +342,9 @@ public function hasController($controller_type) {
* {@inheritdoc}
*/
public function setForm($operation, $class) {
- $this->controllers['form'][$operation] = $class;
+ $controllers = $this->getControllers();
+ $controllers['form'][$operation] = $class;
+ $this->set('controllers', $controllers);
return $this;
}
@@ -350,7 +352,7 @@ public function setForm($operation, $class) {
* {@inheritdoc}
*/
public function setList($class) {
- $this->controllers['list'] = $class;
+ $this->setController('list', $class);
return $this;
}
@@ -358,42 +360,43 @@ public function setList($class) {
* {@inheritdoc}
*/
public function getAdminPermission() {
- return $this->admin_permission ?: FALSE;
+ return $this->get('admin_permission', FALSE);
}
/**
* {@inheritdoc}
*/
public function getPermissionGranularity() {
- return isset($this->permission_granularity) ? $this->permission_granularity : 'entity_type';
+ return $this->get('permission_granularity', 'entity_type');
}
/**
* {@inheritdoc}
*/
public function getBundleKeys() {
- return isset($this->bundle_keys) ? $this->bundle_keys : array();
+ return $this->get('bundle_keys', array());
}
/**
* {@inheritdoc}
*/
public function getBundleKey($name) {
- return isset($this->bundle_keys[$name]) ? $this->bundle_keys[$name] : FALSE;
+ $bundle_keys = $this->getBundleKeys();
+ return isset($bundle_keys[$name]) ? $bundle_keys[$name] : FALSE;
}
/**
* {@inheritdoc}
*/
public function isFieldable() {
- return isset($this->fieldable) ? $this->fieldable : FALSE;
+ return $this->get('fieldable', FALSE);
}
/**
* {@inheritdoc}
*/
public function getLinkTemplates() {
- return isset($this->links) ? $this->links : array();
+ return $this->get('links', array());
}
/**
@@ -424,14 +427,14 @@ public function setLinkTemplate($key, $route_name) {
* {@inheritdoc}
*/
public function getLabelCallback() {
- return isset($this->label_callback) ? $this->label_callback : FALSE;
+ return $this->get('label_callback', FALSE);
}
/**
* {@inheritdoc}
*/
public function setLabelCallback($callback) {
- $this->label_callback = $callback;
+ $this->set('label_callback', $callback);
return $this;
}
@@ -446,70 +449,70 @@ public function hasLabelCallback() {
* {@inheritdoc}
*/
public function getBundleEntityType() {
- return isset($this->bundle_entity_type) ? $this->bundle_entity_type : 'bundle';
+ return $this->get('bundle_entity_type', 'bundle');
}
/**
* {@inheritdoc}
*/
public function getBundleOf() {
- return isset($this->bundle_of) ? $this->bundle_of : FALSE;
+ return $this->get('bundle_of', FALSE);
}
/**
* {@inheritdoc}
*/
public function getBundleLabel() {
- return isset($this->bundle_label) ? $this->bundle_label : FALSE;
+ return $this->get('bundle_label', FALSE);
}
/**
* {@inheritdoc}
*/
public function getBaseTable() {
- return isset($this->base_table) ? $this->base_table : FALSE;
+ return $this->get('base_table', FALSE);
}
/**
* {@inheritdoc}
*/
public function isTranslatable() {
- return !empty($this->translatable);
+ return $this->get('translatable', FALSE);
}
/**
* {@inheritdoc}
*/
public function getConfigPrefix() {
- return isset($this->config_prefix) ? $this->config_prefix : FALSE;
+ return $this->get('config_prefix', FALSE);
}
/**
* {@inheritdoc}
*/
public function getRevisionDataTable() {
- return isset($this->revision_data_table) ? $this->revision_data_table : FALSE;
+ return $this->get('revision_data_table', FALSE);
}
/**
* {@inheritdoc}
*/
public function getRevisionTable() {
- return isset($this->revision_table) ? $this->revision_table : FALSE;
+ return $this->get('revision_table', FALSE);
}
/**
* {@inheritdoc}
*/
public function getDataTable() {
- return isset($this->data_table) ? $this->data_table : FALSE;
+ return $this->get('data_table', FALSE);
}
/**
* {@inheritdoc}
*/
public function getLabel() {
- return isset($this->label) ? $this->label : '';
+ return $this->get('label', '');
}
/**
@@ -523,14 +526,14 @@ public function getLowercaseLabel() {
* {@inheritdoc}
*/
public function getUriCallback() {
- return isset($this->uri_callback) ? $this->uri_callback : FALSE;
+ return $this->get('uri_callback', FALSE);
}
/**
* {@inheritdoc}
*/
public function setUriCallback($callback) {
- $this->uri_callback = $callback;
+ $this->set('uri_callback', $callback);
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment