diff --git a/core/modules/forum/lib/Drupal/forum/ForumContainerItem.php b/core/modules/forum/lib/Drupal/forum/ForumContainerItem.php index a2e1da6..ab185ee 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumContainerItem.php +++ b/core/modules/forum/lib/Drupal/forum/ForumContainerItem.php @@ -24,7 +24,7 @@ class ForumContainerItem extends BooleanItem { static $propertyDefinitions; /** - * Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). + * {@inheritdoc} */ public function getPropertyDefinitions() { diff --git a/core/modules/forum/lib/Drupal/forum/ForumContainerValue.php b/core/modules/forum/lib/Drupal/forum/ForumContainerValue.php index a9beda4..2e20b77 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumContainerValue.php +++ b/core/modules/forum/lib/Drupal/forum/ForumContainerValue.php @@ -17,7 +17,7 @@ class ForumContainerValue extends TypedData { /** - * Implements \Drupal\Core\TypedData\TypedDataInterface::getValue(). + * {@inheritdoc} */ public function getValue() { if (!isset($this->value)) { @@ -27,30 +27,32 @@ public function getValue() { $field = $this->parent->getParent(); $entity = $field->getParent(); $tid = $entity->tid->target_id; - $config = $this->getConfig(); + // @todo Remove when TypedData objects can receive injected dependencies. + // See https://drupal.org/node/2053415. + $config = \Drupal::config('forum.settings'); $this->value = ($entity->bundle() == $config->get('vocabulary') && in_array($entity->id(), $config->get('containers'))); } return $this->value; } /** - * Implements \Drupal\Core\TypedData\TypedDataInterface::setValue(). + * {@inheritdoc} */ public function setValue($value, $notify = TRUE) { if (isset($value)) { - throw new ReadOnlyException('Unable to set a computed property.'); + if (!isset($this->parent)) { + throw new InvalidArgumentException('Computed properties require context for computation.'); + } + $field = $this->parent->getParent(); + $entity = $field->getParent(); + if (!$entity->isNew()) { + throw new ReadOnlyException('Unable to set a computed property.'); + } + else { + // The container value can be set for new entities. + parent::setValue($value, $notify); + } } } - /** - * Retrieves the forum settings config object. - * - * @todo Remove when TypedData objects can receive injected dependencies. - * See https://drupal.org/node/2053415. - * @return - */ - protected function getConfig() { - return \Drupal::config('forum.settings'); - } - }