diff -u b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php --- b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -196,24 +196,21 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { parent::preSave($storage_controller); - // The getQuery() method only exists on ConfigStorageController. - if ($storage_controller instanceof ConfigStorageController) { - // Ensure this entity's UUID does not exist with a different ID, regardless - // of whether it's new or updated. - $matching_entities = $storage_controller->getQuery() - ->condition('uuid', $this->uuid()) - ->execute(); - $matched_entity = reset($matching_entities); - if (!empty($matched_entity) && ($matched_entity != $this->id())) { - throw new ConfigDuplicateUUIDException($this->formatString('Attempt to save a configuration entity %id with UUID %uuid when this UUID is already used for %matched', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%matched' => $matched_entity))); - } + // Ensure this entity's UUID does not exist with a different ID, regardless + // of whether it's new or updated. + $matching_entities = $storage_controller->getQuery() + ->condition('uuid', $this->uuid()) + ->execute(); + $matched_entity = reset($matching_entities); + if (!empty($matched_entity) && ($matched_entity != $this->id())) { + throw new ConfigDuplicateUUIDException($this->formatString('Attempt to save a configuration entity %id with UUID %uuid when this UUID is already used for %matched', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%matched' => $matched_entity))); + } - if (!$this->isNew()) { - $original = $storage_controller->loadUnchanged($this->id()); - // Ensure that the UUID cannot be changed for an existing entity. - if ($original && ($original->uuid() != $this->uuid())) { - throw new ConfigDuplicateUUIDException($this->formatString('Attempt to save a configuration entity %id with UUID %uuid when this entity already exists with UUID %original_uuid', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%original_uuid' => $original->uuid()))); - } + if (!$this->isNew()) { + $original = $storage_controller->loadUnchanged($this->id()); + // Ensure that the UUID cannot be changed for an existing entity. + if ($original && ($original->uuid() != $this->uuid())) { + throw new ConfigDuplicateUUIDException($this->formatString('Attempt to save a configuration entity %id with UUID %uuid when this entity already exists with UUID %original_uuid', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%original_uuid' => $original->uuid()))); } } } diff -u b/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php --- b/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity; +use Drupal\Component\Utility\String; use Drupal\Core\Entity\Plugin\DataType\EntityReference; use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; @@ -174,20 +175,6 @@ } /** - * Wraps check_plain(). - */ - protected function checkPlain($text) { - return check_plain($text); - } - - /** - * Wraps format_string(). - */ - protected function formatString($string, array $args = array()) { - return format_string($string, $args); - } - - /** * Returns the typed data manager. * * @return \Drupal\Core\TypedData\TypedDataManager @@ -423,7 +410,7 @@ if (!isset($this->fields[$property_name][$langcode])) { $definition = $this->getPropertyDefinition($property_name); if (!$definition) { - throw new \InvalidArgumentException('Field ' . $this->checkPlain($property_name) . ' is unknown.'); + throw new \InvalidArgumentException('Field ' . String::checkPlain($property_name) . ' is unknown.'); } // Non-translatable fields are always stored with // Language::LANGCODE_DEFAULT as key. @@ -716,7 +703,7 @@ $languages = $this->languageList(Language::STATE_ALL); if (!isset($languages[$langcode]) || $this->hasTranslation($langcode)) { $message = 'Invalid translation language (@langcode) specified.'; - throw new \InvalidArgumentException($this->formatString($message, array('@langcode' => $langcode))); + throw new \InvalidArgumentException(String::format($message, array('@langcode' => $langcode))); } // Instantiate a new empty entity so default values will be populated in the @@ -761,7 +748,7 @@ } else { $message = 'The specified translation (@langcode) cannot be removed.'; - throw new \InvalidArgumentException($this->formatString($message, array('@langcode' => $langcode))); + throw new \InvalidArgumentException(String::format($message, array('@langcode' => $langcode))); } } @@ -904,7 +891,7 @@ public function createDuplicate() { if ($this->translations[$this->activeLangcode]['status'] == static::TRANSLATION_REMOVED) { $message = 'The entity object refers to a removed translation (@langcode) and cannot be manipulated.'; - throw new \InvalidArgumentException($this->formatString($message, array('@langcode' => $this->activeLangcode))); + throw new \InvalidArgumentException(String::format($message, array('@langcode' => $this->activeLangcode))); } $duplicate = clone $this; diff -u b/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php --- b/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -24,6 +24,20 @@ public $langcode = Language::LANGCODE_NOT_SPECIFIED; /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + + /** + * The UUID generator. + * + * @var \Drupal\Component\Uuid\UuidInterface + */ + protected $uuidGenerator; + + /** * The entity type. * * @var string @@ -74,7 +88,11 @@ * @return \Drupal\Core\Entity\EntityManagerInterface */ protected function entityManager() { - return \Drupal::entityManager(); + if (!$this->entityManager) { + $this->entityManager = \Drupal::entityManager(); + } + + return $this->entityManager; } /** @@ -83,7 +101,11 @@ * @return \Drupal\Component\Uuid\UuidInterface */ protected function uuidGenerator() { - return \Drupal::service('uuid'); + if (!$this->uuidGenerator) { + $this->uuidGenerator = \Drupal::service('uuid'); + } + + return $this->uuidGenerator; } /** diff -u b/core/modules/block/block.module b/core/modules/block/block.module --- b/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -207,7 +207,7 @@ $settings = $block->get('settings'); if ($not_cacheable || in_array($settings['cache'], array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))) { // Non-cached blocks get built immediately. - if ($block->access()) { + if ($block->access('view')) { $build[$key] = entity_view($block, 'block'); } } @@ -239,7 +239,7 @@ $settings = $block->get('settings'); if ($not_cacheable || in_array($settings['cache'], array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))) { // Non-cached blocks get built immediately. - if ($block->access('view')) { + if ($block->access()) { $build[$key] = entity_view($block, 'block'); } } @@ -403,7 +403,7 @@ function _block_get_renderable_block($element) { $block = $element['#block']; // Don't bother to build blocks that aren't accessible. - if ($element['#access'] = $block->access()) { + if ($element['#access'] = $block->access('view')) { $element += entity_view($block, 'block'); } return $element; @@ -435,7 +435,7 @@ function _block_get_renderable_block($element) { $block = $element['#block']; // Don't bother to build blocks that aren't accessible. - if ($element['#access'] = $block->access('view')) { + if ($element['#access'] = $block->access()) { $element += entity_view($block, 'block'); } return $element; diff -u b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php --- b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -17,14 +17,14 @@ /** * The entity under test. * - * @var \Drupal\Core\Config\Entity\ConfigEntityBase + * @var \Drupal\Core\Config\Entity\ConfigEntityBase|\PHPUnit_Framework_MockObject_MockObject */ protected $entity; /** * The entity manager used for testing. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $entityManager; @@ -38,14 +38,14 @@ /** * The route provider used for testing. * - * @var \Drupal\Core\Routing\RouteProvider + * @var \Drupal\Core\Routing\RouteProvider|\PHPUnit_Framework_MockObject_MockObject */ protected $routeProvider; /** * The UUID generator used for testing. * - * @var \Drupal\Component\Uuid\UuidInterface + * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $uuid; @@ -175,7 +175,7 @@ * Tests createDuplicate(). */ public function testCreateDuplicate() { - $this->entityManager->expects($this->at(0)) + $this->entityManager->expects($this->once()) ->method('getDefinition') ->with($this->entityType) ->will($this->returnValue(array( @@ -211,7 +211,7 @@ $entity_b->label = 'bar'; $list = array($entity_a, $entity_b); // Suppress errors because of https://bugs.php.net/bug.php?id=50688. - @usort($list, array('\Drupal\Core\Config\Entity\ConfigEntityBase', 'sort')); + @usort($list, '\Drupal\Core\Config\Entity\ConfigEntityBase::sort'); $this->assertSame(spl_object_hash($entity_b), spl_object_hash($list[0])); $entity_a->weight = 0; $entity_b->weight = 1; diff -u b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php --- b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -24,14 +24,14 @@ /** * The entity under test. * - * @var \Drupal\Core\Entity\ContentEntityBase + * @var \Drupal\Core\Entity\ContentEntityBase|\PHPUnit_Framework_MockObject_MockObject */ protected $entity; /** * The entity manager used for testing. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $entityManager; @@ -45,14 +45,14 @@ /** * The typed data manager used for testing. * - * @var \Drupal\Core\TypedData\TypedDataManager + * @var \Drupal\Core\TypedData\TypedDataManager|\PHPUnit_Framework_MockObject_MockObject */ protected $typedDataManager; /** * The UUID generator used for testing. * - * @var \Drupal\Component\Uuid\UuidInterface + * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $uuid; @@ -93,18 +93,12 @@ $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\ContentEntityBase') ->setConstructorArgs(array($values, $this->entityType, $this->bundle)) - ->setMethods(array('checkPlain', 'entityManager', 'formatString', 'languageList', 'languageLoad', 'typedDataManager', 'uuidGenerator')) + ->setMethods(array('entityManager', 'languageList', 'languageLoad', 'typedDataManager', 'uuidGenerator')) ->getMockForAbstractClass(); $this->entity->expects($this->any()) - ->method('checkPlain') - ->will($this->returnArgument(0)); - $this->entity->expects($this->any()) ->method('entityManager') ->will($this->returnValue($this->entityManager)); $this->entity->expects($this->any()) - ->method('formatString') - ->will($this->returnArgument(0)); - $this->entity->expects($this->any()) ->method('languageList') ->will($this->returnValue(array())); $this->entity->expects($this->any()) diff -u b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php --- b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php @@ -17,14 +17,14 @@ /** * The entity under test. * - * @var \Drupal\Core\Entity\Entity + * @var \Drupal\Core\Entity\Entity|\PHPUnit_Framework_MockObject_MockObject */ protected $entity; /** * The entity manager used for testing. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $entityManager; @@ -38,14 +38,14 @@ /** * The route provider used for testing. * - * @var \Drupal\Core\Routing\RouteProvider + * @var \Drupal\Core\Routing\RouteProvider|\PHPUnit_Framework_MockObject_MockObject */ protected $routeProvider; /** * The UUID generator used for testing. * - * @var \Drupal\Component\Uuid\UuidInterface + * @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $uuid;