Update to Drupal 8.0.0-rc3. For more information, see https://www.drupal.org/node/2608078
This commit is contained in:
parent
6419a031d7
commit
4afb23bbd3
762 changed files with 20080 additions and 6368 deletions
|
@ -155,11 +155,11 @@ class AccessManager implements AccessManagerInterface {
|
|||
* @param \Drupal\Component\Utility\ArgumentsResolverInterface $arguments_resolver
|
||||
* The parametrized arguments resolver instance.
|
||||
*
|
||||
* @throws \Drupal\Core\Access\AccessException
|
||||
* Thrown when the access check returns an invalid value.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResultInterface
|
||||
* The access result.
|
||||
*
|
||||
* @throws \Drupal\Core\Access\AccessException
|
||||
* Thrown when the access check returns an invalid value.
|
||||
*/
|
||||
protected function performCheck($service_id, ArgumentsResolverInterface $arguments_resolver) {
|
||||
$callable = $this->checkProvider->loadCheck($service_id);
|
||||
|
|
|
@ -148,6 +148,16 @@ class AjaxResponseAttachmentsProcessor implements AttachmentsResponseProcessorIn
|
|||
$css_assets = $this->assetResolver->getCssAssets($assets, $optimize_css);
|
||||
list($js_assets_header, $js_assets_footer) = $this->assetResolver->getJsAssets($assets, $optimize_js);
|
||||
|
||||
// First, AttachedAssets::setLibraries() ensures duplicate libraries are
|
||||
// removed: it converts it to a set of libraries if necessary. Second,
|
||||
// AssetResolver::getJsSettings() ensures $assets contains the final set of
|
||||
// JavaScript settings. AttachmentsResponseProcessorInterface also mandates
|
||||
// that the response it processes contains the final attachment values, so
|
||||
// update both the 'library' and 'drupalSettings' attachments accordingly.
|
||||
$attachments['library'] = $assets->getLibraries();
|
||||
$attachments['drupalSettings'] = $assets->getSettings();
|
||||
$response->setAttachments($attachments);
|
||||
|
||||
// Render the HTML to load these files, and add AJAX commands to insert this
|
||||
// HTML in the page. Settings are handled separately, afterwards.
|
||||
$settings = [];
|
||||
|
|
|
@ -42,7 +42,7 @@ class CloseDialogCommand implements CommandInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Ajax\CommandInterface::render().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render() {
|
||||
return array(
|
||||
|
|
|
@ -54,7 +54,7 @@ class SetDialogOptionCommand implements CommandInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Ajax\CommandInterface::render().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render() {
|
||||
return array(
|
||||
|
|
|
@ -39,7 +39,7 @@ class ArchiverManager extends DefaultPluginManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\Component\Plugin\PluginManagerBase::createInstance().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createInstance($plugin_id, array $configuration = array()) {
|
||||
$plugin_definition = $this->getDefinition($plugin_id);
|
||||
|
@ -48,7 +48,7 @@ class ArchiverManager extends DefaultPluginManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\PluginManagerInterface::getInstance().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInstance(array $options) {
|
||||
$filepath = $options['filepath'];
|
||||
|
|
|
@ -334,6 +334,9 @@ class AssetResolver implements AssetResolverInterface {
|
|||
// Allow modules and themes to alter the JavaScript settings.
|
||||
$this->moduleHandler->alter('js_settings', $settings, $assets);
|
||||
$this->themeManager->alter('js_settings', $settings, $assets);
|
||||
// Update the $assets object accordingly, so that it reflects the final
|
||||
// settings.
|
||||
$assets->setSettings($settings);
|
||||
$settings_as_inline_javascript = [
|
||||
'type' => 'setting',
|
||||
'group' => JS_SETTING,
|
||||
|
|
|
@ -69,6 +69,8 @@ interface AssetResolverInterface {
|
|||
*
|
||||
* @param \Drupal\Core\Asset\AttachedAssetsInterface $assets
|
||||
* The assets attached to the current response.
|
||||
* Note that this object is modified to reflect the final JavaScript
|
||||
* settings assets.
|
||||
* @param bool $optimize
|
||||
* Whether to apply the JavaScript asset collection optimizer, to return
|
||||
* optimized JavaScript asset collections rather than an unoptimized ones.
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
namespace Drupal\Core\Asset;
|
||||
|
||||
use Drupal\Core\Cache\CacheCollectorInterface;
|
||||
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
|
||||
|
||||
/**
|
||||
* Discovers available asset libraries in Drupal.
|
||||
|
@ -22,13 +21,6 @@ class LibraryDiscovery implements LibraryDiscoveryInterface {
|
|||
*/
|
||||
protected $collector;
|
||||
|
||||
/**
|
||||
* The cache tag invalidator.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
|
||||
*/
|
||||
protected $cacheTagInvalidator;
|
||||
|
||||
/**
|
||||
* The final library definitions, statically cached.
|
||||
*
|
||||
|
@ -44,16 +36,9 @@ class LibraryDiscovery implements LibraryDiscoveryInterface {
|
|||
*
|
||||
* @param \Drupal\Core\Cache\CacheCollectorInterface $library_discovery_collector
|
||||
* The library discovery cache collector.
|
||||
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tag_invalidator
|
||||
* The cache tag invalidator.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
|
||||
* The theme manager.
|
||||
*/
|
||||
public function __construct(CacheCollectorInterface $library_discovery_collector, CacheTagsInvalidatorInterface $cache_tag_invalidator) {
|
||||
public function __construct(CacheCollectorInterface $library_discovery_collector) {
|
||||
$this->collector = $library_discovery_collector;
|
||||
$this->cacheTagInvalidator = $cache_tag_invalidator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +49,6 @@ class LibraryDiscovery implements LibraryDiscoveryInterface {
|
|||
$libraries = $this->collector->get($extension);
|
||||
$this->libraryDefinitions[$extension] = [];
|
||||
foreach ($libraries as $name => $definition) {
|
||||
$library_name = "$extension/$name";
|
||||
$this->libraryDefinitions[$extension][$name] = $definition;
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +68,6 @@ class LibraryDiscovery implements LibraryDiscoveryInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearCachedDefinitions() {
|
||||
$this->cacheTagInvalidator->invalidateTags(['library_info']);
|
||||
$this->libraryDefinitions = [];
|
||||
$this->collector->clear();
|
||||
}
|
||||
|
|
|
@ -88,7 +88,6 @@ class LibraryDiscoveryCollector extends CacheCollector {
|
|||
return $this->storage[$key];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the library definitions for a given extension.
|
||||
*
|
||||
|
@ -172,4 +171,13 @@ class LibraryDiscoveryCollector extends CacheCollector {
|
|||
}
|
||||
return $library_definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset() {
|
||||
parent::reset();
|
||||
$this->cid = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Plugin\Block\PageTitleBlock.
|
||||
* Contains \Drupal\Core\Block\Plugin\Block\PageTitleBlock.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Block\Plugin\Block;
|
||||
|
|
|
@ -74,7 +74,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::get().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($cid, $allow_invalid = FALSE) {
|
||||
foreach ($this->backends as $index => $backend) {
|
||||
|
@ -94,7 +94,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
$return = array();
|
||||
|
@ -125,7 +125,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::set().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
|
||||
foreach ($this->backends as $backend) {
|
||||
|
@ -143,7 +143,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::delete().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($cid) {
|
||||
foreach ($this->backends as $backend) {
|
||||
|
@ -152,7 +152,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteMultiple(array $cids) {
|
||||
foreach ($this->backends as $backend) {
|
||||
|
@ -161,7 +161,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteAll() {
|
||||
foreach ($this->backends as $backend) {
|
||||
|
@ -170,7 +170,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidate().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidate($cid) {
|
||||
foreach ($this->backends as $backend) {
|
||||
|
@ -179,7 +179,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidateMultiple(array $cids) {
|
||||
foreach ($this->backends as $backend) {
|
||||
|
@ -188,7 +188,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateTags().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidateTags(array $tags) {
|
||||
foreach ($this->backends as $backend) {
|
||||
|
@ -199,7 +199,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidateAll() {
|
||||
foreach ($this->backends as $backend) {
|
||||
|
@ -208,7 +208,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function garbageCollection() {
|
||||
foreach ($this->backends as $backend) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Cache\CacheableResponse.
|
||||
* Contains \Drupal\Core\Cache\CacheableJsonResponse.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Cache;
|
||||
|
|
|
@ -61,7 +61,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::get().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($cid, $allow_invalid = FALSE) {
|
||||
$cids = array($cid);
|
||||
|
@ -70,7 +70,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
$cid_mapping = array();
|
||||
|
@ -240,14 +240,14 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::delete().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($cid) {
|
||||
$this->deleteMultiple(array($cid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteMultiple(array $cids) {
|
||||
$cids = array_values(array_map(array($this, 'normalizeCid'), $cids));
|
||||
|
@ -270,7 +270,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteAll() {
|
||||
try {
|
||||
|
@ -287,14 +287,14 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidate().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidate($cid) {
|
||||
$this->invalidateMultiple(array($cid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidateMultiple(array $cids) {
|
||||
$cids = array_values(array_map(array($this, 'normalizeCid'), $cids));
|
||||
|
@ -313,7 +313,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidateAll() {
|
||||
try {
|
||||
|
@ -327,7 +327,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function garbageCollection() {
|
||||
try {
|
||||
|
|
|
@ -34,7 +34,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::get().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($cid, $allow_invalid = FALSE) {
|
||||
if (isset($this->cache[$cid])) {
|
||||
|
@ -46,7 +46,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
$ret = array();
|
||||
|
@ -104,7 +104,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::set().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
|
||||
assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($tags)', 'Cache Tags must be strings.');
|
||||
|
@ -130,28 +130,28 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::delete().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($cid) {
|
||||
unset($this->cache[$cid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteMultiple(array $cids) {
|
||||
$this->cache = array_diff_key($this->cache, array_flip($cids));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteAll() {
|
||||
$this->cache = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidate().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidate($cid) {
|
||||
if (isset($this->cache[$cid])) {
|
||||
|
@ -160,7 +160,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidateMultiple(array $cids) {
|
||||
foreach ($cids as $cid) {
|
||||
|
@ -180,7 +180,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidateAll() {
|
||||
foreach ($this->cache as $cid => $item) {
|
||||
|
@ -189,7 +189,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection()
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function garbageCollection() {
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class MemoryCounterBackend extends MemoryBackend {
|
|||
protected $counter = array();
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Cache\CacheBackendInterface::get().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($cid, $allow_invalid = FALSE) {
|
||||
$this->increaseCounter(__FUNCTION__, $cid);
|
||||
|
@ -34,7 +34,7 @@ class MemoryCounterBackend extends MemoryBackend {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Cache\CacheBackendInterface::set().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
|
||||
$this->increaseCounter(__FUNCTION__, $cid);
|
||||
|
@ -42,7 +42,7 @@ class MemoryCounterBackend extends MemoryBackend {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Cache\CacheBackendInterface::delete().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($cid) {
|
||||
$this->increaseCounter(__FUNCTION__, $cid);
|
||||
|
|
|
@ -31,21 +31,21 @@ class NullBackend implements CacheBackendInterface {
|
|||
public function __construct($bin) {}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::get().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($cid, $allow_invalid = FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::set().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {}
|
||||
|
||||
|
@ -55,37 +55,37 @@ class NullBackend implements CacheBackendInterface {
|
|||
public function setMultiple(array $items = array()) {}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::delete().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($cid) {}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteMultiple(array $cids) {}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteAll() {}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidate().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidate($cid) {}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidateMultiple(array $cids) {}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::invalidateAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidateAll() {}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function garbageCollection() {}
|
||||
|
||||
|
|
80
core/lib/Drupal/Core/Cache/UseCacheBackendTrait.php
Normal file
80
core/lib/Drupal/Core/Cache/UseCacheBackendTrait.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Cache\UseCacheBackendTrait.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Cache;
|
||||
|
||||
/**
|
||||
* Provides methods to use a cache backend while respecting a 'use caches' flag.
|
||||
*/
|
||||
trait UseCacheBackendTrait {
|
||||
|
||||
/**
|
||||
* Cache backend instance.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheBackendInterface
|
||||
*/
|
||||
protected $cacheBackend;
|
||||
|
||||
/**
|
||||
* Flag whether caches should be used or skipped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useCaches = TRUE;
|
||||
|
||||
/**
|
||||
* Fetches from the cache backend, respecting the use caches flag.
|
||||
*
|
||||
* @param string $cid
|
||||
* The cache ID of the data to retrieve.
|
||||
*
|
||||
* @return object|false
|
||||
* The cache item or FALSE on failure.
|
||||
*
|
||||
* @see \Drupal\Core\Cache\CacheBackendInterface::get()
|
||||
*/
|
||||
protected function cacheGet($cid) {
|
||||
if ($this->useCaches && $this->cacheBackend) {
|
||||
return $this->cacheBackend->get($cid);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores data in the persistent cache, respecting the use caches flag.
|
||||
*
|
||||
* @param string $cid
|
||||
* The cache ID of the data to store.
|
||||
* @param mixed $data
|
||||
* The data to store in the cache.
|
||||
* Some storage engines only allow objects up to a maximum of 1MB in size to
|
||||
* be stored by default. When caching large arrays or similar, take care to
|
||||
* ensure $data does not exceed this size.
|
||||
* @param int $expire
|
||||
* One of the following values:
|
||||
* - CacheBackendInterface::CACHE_PERMANENT: Indicates that the item should
|
||||
* not be removed unless it is deleted explicitly.
|
||||
* - A Unix timestamp: Indicates that the item will be considered invalid
|
||||
* after this time, i.e. it will not be returned by get() unless
|
||||
* $allow_invalid has been set to TRUE. When the item has expired, it may
|
||||
* be permanently deleted by the garbage collector at any time.
|
||||
* @param array $tags
|
||||
* An array of tags to be stored with the cache item. These should normally
|
||||
* identify objects used to build the cache item, which should trigger
|
||||
* cache invalidation when updated. For example if a cached item represents
|
||||
* a node, both the node ID and the author's user ID might be passed in as
|
||||
* tags. For example array('node' => array(123), 'user' => array(92)).
|
||||
*
|
||||
* @see \Drupal\Core\Cache\CacheBackendInterface::set()
|
||||
*/
|
||||
protected function cacheSet($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
|
||||
if ($this->cacheBackend && $this->useCaches) {
|
||||
$this->cacheBackend->set($cid, $data, $expire, $tags);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Command\DbDumpCommand.
|
||||
* Contains \Drupal\Core\Command\DbImportCommand.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Command;
|
||||
|
|
|
@ -31,6 +31,8 @@ class Composer {
|
|||
'fabpot/goutte' => ['Goutte/Tests'],
|
||||
'guzzlehttp/promises' => ['tests'],
|
||||
'guzzlehttp/psr7' => ['tests'],
|
||||
'jcalderonzumba/gastonjs' => ['docs', 'examples', 'tests'],
|
||||
'jcalderonzumba/mink-phantomjs-driver' => ['tests'],
|
||||
'masterminds/html5' => ['test'],
|
||||
'mikey179/vfsStream' => ['src/test'],
|
||||
'phpdocumentor/reflection-docblock' => ['tests'],
|
||||
|
|
|
@ -65,7 +65,7 @@ class ConditionManager extends DefaultPluginManager implements ExecutableManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Executable\ExecutableManagerInterface::execute().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute(ExecutableInterface $condition) {
|
||||
$result = $condition->evaluate();
|
||||
|
|
|
@ -55,7 +55,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::exists().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exists($name) {
|
||||
// The cache would read in the entire data (instead of only checking whether
|
||||
|
@ -65,7 +65,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::read().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($name) {
|
||||
$cache_key = $this->getCacheKey($name);
|
||||
|
@ -123,7 +123,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::write().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($name, array $data) {
|
||||
if ($this->storage->write($name, $data)) {
|
||||
|
@ -137,7 +137,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::delete().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($name) {
|
||||
// If the cache was the first to be deleted, another process might start
|
||||
|
@ -151,7 +151,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::rename().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rename($name, $new_name) {
|
||||
// If the cache was the first to be deleted, another process might start
|
||||
|
@ -166,14 +166,14 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::encode().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data) {
|
||||
return $this->storage->encode($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::decode().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function decode($raw) {
|
||||
return $this->storage->decode($raw);
|
||||
|
@ -215,7 +215,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::deleteAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteAll($prefix = '') {
|
||||
// If the cache was the first to be deleted, another process might start
|
||||
|
|
|
@ -111,25 +111,26 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
}
|
||||
else {
|
||||
// If the configuration object does not exist in the configuration
|
||||
// storage, create a new object and add it to the static cache.
|
||||
$cache_key = $this->getConfigCacheKey($name, $immutable);
|
||||
$this->cache[$cache_key] = $this->createConfigObject($name, $immutable);
|
||||
// storage, create a new object.
|
||||
$config = $this->createConfigObject($name, $immutable);
|
||||
|
||||
if ($immutable) {
|
||||
// Get and apply any overrides.
|
||||
$overrides = $this->loadOverrides(array($name));
|
||||
if (isset($overrides[$name])) {
|
||||
$this->cache[$cache_key]->setModuleOverride($overrides[$name]);
|
||||
$config->setModuleOverride($overrides[$name]);
|
||||
}
|
||||
// Apply any settings.php overrides.
|
||||
if (isset($GLOBALS['config'][$name])) {
|
||||
$this->cache[$cache_key]->setSettingsOverride($GLOBALS['config'][$name]);
|
||||
$config->setSettingsOverride($GLOBALS['config'][$name]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->propagateConfigOverrideCacheability($cache_key, $name);
|
||||
foreach ($this->configFactoryOverrides as $override) {
|
||||
$config->addCacheableDependency($override->getCacheableMetadata($name));
|
||||
}
|
||||
|
||||
return $this->cache[$cache_key];
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -454,10 +454,10 @@ class ConfigImporter {
|
|||
/**
|
||||
* Imports the changelist to the target storage.
|
||||
*
|
||||
* @throws \Drupal\Core\Config\ConfigException
|
||||
*
|
||||
* @return \Drupal\Core\Config\ConfigImporter
|
||||
* The ConfigImporter instance.
|
||||
*
|
||||
* @throws \Drupal\Core\Config\ConfigException
|
||||
*/
|
||||
public function import() {
|
||||
if ($this->hasUnprocessedConfigurationChanges()) {
|
||||
|
@ -828,10 +828,10 @@ class ConfigImporter {
|
|||
* @param string $name
|
||||
* The name of the configuration to process.
|
||||
*
|
||||
* @throws \Drupal\Core\Config\ConfigImporterException
|
||||
*
|
||||
* @return bool
|
||||
* TRUE is to continue processing, FALSE otherwise.
|
||||
*
|
||||
* @throws \Drupal\Core\Config\ConfigImporterException
|
||||
*/
|
||||
protected function checkOp($collection, $op, $name) {
|
||||
if ($op == 'rename') {
|
||||
|
@ -939,13 +939,13 @@ class ConfigImporter {
|
|||
* @param string $name
|
||||
* The name of the configuration to process.
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\EntityStorageException
|
||||
* Thrown if the data is owned by an entity type, but the entity storage
|
||||
* does not support imports.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the configuration was imported as a configuration entity. FALSE
|
||||
* otherwise.
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\EntityStorageException
|
||||
* Thrown if the data is owned by an entity type, but the entity storage
|
||||
* does not support imports.
|
||||
*/
|
||||
protected function importInvokeOwner($collection, $op, $name) {
|
||||
// Renames are handled separately.
|
||||
|
@ -989,14 +989,14 @@ class ConfigImporter {
|
|||
* The rename configuration name, as provided by
|
||||
* \Drupal\Core\Config\StorageComparer::createRenameName().
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\EntityStorageException
|
||||
* Thrown if the data is owned by an entity type, but the entity storage
|
||||
* does not support imports.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the configuration was imported as a configuration entity. FALSE
|
||||
* otherwise.
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\EntityStorageException
|
||||
* Thrown if the data is owned by an entity type, but the entity storage
|
||||
* does not support imports.
|
||||
*
|
||||
* @see \Drupal\Core\Config\ConfigImporter::createRenameName()
|
||||
*/
|
||||
protected function importInvokeRename($collection, $rename_name) {
|
||||
|
|
|
@ -67,7 +67,7 @@ class DatabaseStorage implements StorageInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::exists().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exists($name) {
|
||||
try {
|
||||
|
@ -247,7 +247,7 @@ class DatabaseStorage implements StorageInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::encode().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data) {
|
||||
return serialize($data);
|
||||
|
|
|
@ -111,7 +111,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
|||
protected $trustedData = FALSE;
|
||||
|
||||
/**
|
||||
* Overrides Entity::__construct().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $values, $entity_type) {
|
||||
parent::__construct($values, $entity_type);
|
||||
|
|
|
@ -138,7 +138,7 @@ class ConfigEntityStorage extends EntityStorageBase implements ConfigEntityStora
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Entity\EntityStorageInterface::deleteRevision().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteRevision($revision_id) {
|
||||
return NULL;
|
||||
|
|
|
@ -20,7 +20,7 @@ use Drupal\Core\Entity\Query\QueryException;
|
|||
class Condition extends ConditionBase {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Entity\Query\ConditionInterface::compile().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compile($configs) {
|
||||
$and = strtoupper($this->conjunction) == 'AND';
|
||||
|
@ -86,14 +86,14 @@ class Condition extends ConditionBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Entity\Query\ConditionInterface::exists().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exists($field, $langcode = NULL) {
|
||||
return $this->condition($field, NULL, 'IS NOT NULL', $langcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Entity\Query\ConditionInterface::notExists().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notExists($field, $langcode = NULL) {
|
||||
return $this->condition($field, NULL, 'IS NULL', $langcode);
|
||||
|
|
|
@ -80,7 +80,7 @@ class Query extends QueryBase implements QueryInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Entity\Query\QueryInterface::execute().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute() {
|
||||
// Load the relevant config records.
|
||||
|
|
|
@ -80,7 +80,7 @@ class FileStorage implements StorageInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::exists().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exists($name) {
|
||||
return file_exists($this->getFilePath($name));
|
||||
|
@ -146,7 +146,7 @@ class FileStorage implements StorageInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::delete().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($name) {
|
||||
if (!$this->exists($name)) {
|
||||
|
@ -160,7 +160,7 @@ class FileStorage implements StorageInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::rename().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rename($name, $new_name) {
|
||||
$status = @rename($this->getFilePath($name), $this->getFilePath($new_name));
|
||||
|
@ -171,14 +171,14 @@ class FileStorage implements StorageInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::encode().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data) {
|
||||
return Yaml::encode($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::decode().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function decode($raw) {
|
||||
$data = Yaml::decode($raw);
|
||||
|
@ -190,7 +190,7 @@ class FileStorage implements StorageInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::listAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listAll($prefix = '') {
|
||||
$dir = $this->getCollectionDirectory();
|
||||
|
@ -216,7 +216,7 @@ class FileStorage implements StorageInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::deleteAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteAll($prefix = '') {
|
||||
$success = TRUE;
|
||||
|
|
|
@ -129,7 +129,7 @@ class InstallStorage extends FileStorage {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::listAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listAll($prefix = '') {
|
||||
$names = array_keys($this->getAllFolders());
|
||||
|
|
|
@ -24,70 +24,70 @@ namespace Drupal\Core\Config;
|
|||
class NullStorage implements StorageInterface {
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::exists().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exists($name) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::read().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($name) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::readMultiple().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function readMultiple(array $names) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::write().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($name, array $data) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::delete().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($name) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::rename().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rename($name, $new_name) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::encode().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::decode().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function decode($raw) {
|
||||
return $raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::listAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listAll($prefix = '') {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Config\StorageInterface::deleteAll().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteAll($prefix = '') {
|
||||
return FALSE;
|
||||
|
|
|
@ -115,7 +115,7 @@ abstract class ArrayElement extends Element implements \IteratorAggregate, Typed
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements IteratorAggregate::getIterator();
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIterator() {
|
||||
return new \ArrayIterator($this->getElements());
|
||||
|
|
|
@ -45,11 +45,11 @@ interface TypedConfigInterface extends TraversableTypedDataInterface {
|
|||
* elements can be get using multiple dot delimited names, for example,
|
||||
* 'page.front'.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* If an invalid property name is given.
|
||||
*
|
||||
* @return \Drupal\Core\TypedData\TypedDataInterface
|
||||
* The property object.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* If an invalid property name is given.
|
||||
*/
|
||||
public function get($name);
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ class TitleResolver implements TitleResolverInterface {
|
|||
if (($raw_parameters = $request->attributes->get('_raw_variables'))) {
|
||||
foreach ($raw_parameters->all() as $key => $value) {
|
||||
$args['@' . $key] = $value;
|
||||
$args['!' . $key] = $value;
|
||||
$args['%' . $key] = $value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ use Drupal\Component\Utility\Unicode;
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* MySQL implementation of \Drupal\Core\Database\Connection.
|
||||
*/
|
||||
class Connection extends DatabaseConnection {
|
||||
|
||||
/**
|
||||
|
@ -33,6 +36,16 @@ class Connection extends DatabaseConnection {
|
|||
*/
|
||||
const UNSUPPORTED_CHARSET = 2019;
|
||||
|
||||
/**
|
||||
* Driver-specific error code for "Unknown character set" error.
|
||||
*/
|
||||
const UNKNOWN_CHARSET = 1115;
|
||||
|
||||
/**
|
||||
* SQLSTATE error code for "Syntax error or access rule violation".
|
||||
*/
|
||||
const SQLSTATE_SYNTAX_ERROR = 42000;
|
||||
|
||||
/**
|
||||
* Flag to indicate if the cleanup function in __destruct() should run.
|
||||
*
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\mysql;
|
|||
|
||||
use Drupal\Core\Database\Query\Delete as QueryDelete;
|
||||
|
||||
/**
|
||||
* MySQL implementation of \Drupal\Core\Database\Query\Delete.
|
||||
*/
|
||||
class Delete extends QueryDelete { }
|
||||
|
|
|
@ -9,6 +9,9 @@ namespace Drupal\Core\Database\Driver\mysql;
|
|||
|
||||
use Drupal\Core\Database\Query\Insert as QueryInsert;
|
||||
|
||||
/**
|
||||
* MySQL implementation of \Drupal\Core\Database\Query\Insert.
|
||||
*/
|
||||
class Insert extends QueryInsert {
|
||||
|
||||
public function execute() {
|
||||
|
|
|
@ -71,7 +71,7 @@ class Tasks extends InstallTasks {
|
|||
}
|
||||
catch (\Exception $e) {
|
||||
// Detect utf8mb4 incompability.
|
||||
if ($e->getCode() == Connection::UNSUPPORTED_CHARSET) {
|
||||
if ($e->getCode() == Connection::UNSUPPORTED_CHARSET || ($e->getCode() == Connection::SQLSTATE_SYNTAX_ERROR && $e->errorInfo[1] == Connection::UNKNOWN_CHARSET)) {
|
||||
$this->fail(t('Your MySQL server and PHP MySQL driver must support utf8mb4 character encoding. Make sure to use a database system that supports this (such as MySQL/MariaDB/Percona 5.5.3 and up), and that the utf8mb4 character set is compiled in. See the <a href=":documentation" target="_blank">MySQL documentation</a> for more information.', array(':documentation' => 'https://dev.mysql.com/doc/refman/5.0/en/cannot-initialize-character-set.html')));
|
||||
$info = Database::getConnectionInfo();
|
||||
$info_copy = $info;
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\mysql;
|
|||
|
||||
use Drupal\Core\Database\Query\Merge as QueryMerge;
|
||||
|
||||
/**
|
||||
* MySQL implementation of \Drupal\Core\Database\Query\Merge.
|
||||
*/
|
||||
class Merge extends QueryMerge { }
|
||||
|
|
|
@ -19,6 +19,9 @@ use Drupal\Component\Utility\Unicode;
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* MySQL implementation of \Drupal\Core\Database\Schema.
|
||||
*/
|
||||
class Schema extends DatabaseSchema {
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\mysql;
|
|||
|
||||
use Drupal\Core\Database\Query\Select as QuerySelect;
|
||||
|
||||
/**
|
||||
* MySQL implementation of \Drupal\Core\Database\Query\Select.
|
||||
*/
|
||||
class Select extends QuerySelect { }
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\mysql;
|
|||
|
||||
use Drupal\Core\Database\Transaction as DatabaseTransaction;
|
||||
|
||||
/**
|
||||
* MySQL implementation of \Drupal\Core\Database\Transaction.
|
||||
*/
|
||||
class Transaction extends DatabaseTransaction { }
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\mysql;
|
|||
|
||||
use Drupal\Core\Database\Query\Truncate as QueryTruncate;
|
||||
|
||||
/**
|
||||
* MySQL implementation of \Drupal\Core\Database\Query\Truncate.
|
||||
*/
|
||||
class Truncate extends QueryTruncate { }
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\mysql;
|
|||
|
||||
use Drupal\Core\Database\Query\Update as QueryUpdate;
|
||||
|
||||
/**
|
||||
* MySQL implementation of \Drupal\Core\Database\Query\Update.
|
||||
*/
|
||||
class Update extends QueryUpdate { }
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Drupal\Core\Database\Driver\mysql;
|
|||
use Drupal\Core\Database\Query\Upsert as QueryUpsert;
|
||||
|
||||
/**
|
||||
* Implements the Upsert query for the MySQL database driver.
|
||||
* MySQL implementation of \Drupal\Core\Database\Query\Upsert.
|
||||
*/
|
||||
class Upsert extends QueryUpsert {
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@ use Drupal\Core\Database\DatabaseNotFoundException;
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* PostgreSQL implementation of \Drupal\Core\Database\Connection.
|
||||
*/
|
||||
class Connection extends DatabaseConnection {
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,9 @@ namespace Drupal\Core\Database\Driver\pgsql;
|
|||
|
||||
use Drupal\Core\Database\Query\Delete as QueryDelete;
|
||||
|
||||
/**
|
||||
* PostgreSQL implementation of \Drupal\Core\Database\Query\Delete.
|
||||
*/
|
||||
class Delete extends QueryDelete {
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,6 +15,9 @@ use Drupal\Core\Database\Query\Insert as QueryInsert;
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* PostgreSQL implementation of \Drupal\Core\Database\Query\Insert.
|
||||
*/
|
||||
class Insert extends QueryInsert {
|
||||
|
||||
public function execute() {
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\pgsql;
|
|||
|
||||
use Drupal\Core\Database\Query\Merge as QueryMerge;
|
||||
|
||||
/**
|
||||
* PostgreSQL implementation of \Drupal\Core\Database\Query\Merge.
|
||||
*/
|
||||
class Merge extends QueryMerge { }
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Drupal\Core\Database\Driver\pgsql;
|
|||
use Drupal\Core\Database\Query\Upsert as QueryUpsert;
|
||||
|
||||
/**
|
||||
* Implements the native Upsert query for the PostgreSQL database driver.
|
||||
* PostgreSQL implementation of native \Drupal\Core\Database\Query\Upsert.
|
||||
*
|
||||
* @see http://www.postgresql.org/docs/9.5/static/sql-insert.html#SQL-ON-CONFLICT
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,9 @@ use Drupal\Core\Database\Schema as DatabaseSchema;
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* PostgreSQL implementation of \Drupal\Core\Database\Schema.
|
||||
*/
|
||||
class Schema extends DatabaseSchema {
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,6 +14,9 @@ use Drupal\Core\Database\Query\Select as QuerySelect;
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* PostgreSQL implementation of \Drupal\Core\Database\Query\Select.
|
||||
*/
|
||||
class Select extends QuerySelect {
|
||||
|
||||
public function orderRandom() {
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\pgsql;
|
|||
|
||||
use Drupal\Core\Database\Transaction as DatabaseTransaction;
|
||||
|
||||
/**
|
||||
* PostgreSQL implementation of \Drupal\Core\Database\Transaction.
|
||||
*/
|
||||
class Transaction extends DatabaseTransaction { }
|
||||
|
|
|
@ -9,6 +9,9 @@ namespace Drupal\Core\Database\Driver\pgsql;
|
|||
|
||||
use Drupal\Core\Database\Query\Truncate as QueryTruncate;
|
||||
|
||||
/**
|
||||
* PostgreSQL implementation of \Drupal\Core\Database\Query\Truncate.
|
||||
*/
|
||||
class Truncate extends QueryTruncate {
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,6 +11,9 @@ use Drupal\Core\Database\Database;
|
|||
use Drupal\Core\Database\Query\Update as QueryUpdate;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
|
||||
/**
|
||||
* PostgreSQL implementation of \Drupal\Core\Database\Query\Update.
|
||||
*/
|
||||
class Update extends QueryUpdate {
|
||||
|
||||
public function execute() {
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Drupal\Core\Database\Driver\pgsql;
|
|||
use Drupal\Core\Database\Query\Upsert as QueryUpsert;
|
||||
|
||||
/**
|
||||
* Implements the Upsert query for the PostgreSQL database driver.
|
||||
* PostgreSQL implementation of \Drupal\Core\Database\Query\Upsert.
|
||||
*/
|
||||
class Upsert extends QueryUpsert {
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use Drupal\Core\Database\DatabaseNotFoundException;
|
|||
use Drupal\Core\Database\Connection as DatabaseConnection;
|
||||
|
||||
/**
|
||||
* Specific SQLite implementation of DatabaseConnection.
|
||||
* SQLite implementation of \Drupal\Core\Database\Connection.
|
||||
*/
|
||||
class Connection extends DatabaseConnection {
|
||||
|
||||
|
|
|
@ -10,6 +10,6 @@ namespace Drupal\Core\Database\Driver\sqlite;
|
|||
use Drupal\Core\Database\Query\Delete as QueryDelete;
|
||||
|
||||
/**
|
||||
* SQLite specific implementation of \Drupal\Core\Database\Query\Delete.
|
||||
* SQLite implementation of \Drupal\Core\Database\Query\Delete.
|
||||
*/
|
||||
class Delete extends QueryDelete { }
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Drupal\Core\Database\Driver\sqlite;
|
|||
use Drupal\Core\Database\Query\Insert as QueryInsert;
|
||||
|
||||
/**
|
||||
* SQLite specific implementation of InsertQuery.
|
||||
* SQLite implementation of \Drupal\Core\Database\Query\Insert.
|
||||
*
|
||||
* We ignore all the default fields and use the clever SQLite syntax:
|
||||
* INSERT INTO table DEFAULT VALUES
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\sqlite;
|
|||
|
||||
use Drupal\Core\Database\Query\Merge as QueryMerge;
|
||||
|
||||
/**
|
||||
* SQLite implementation of \Drupal\Core\Database\Query\Merge.
|
||||
*/
|
||||
class Merge extends QueryMerge { }
|
||||
|
|
|
@ -17,6 +17,9 @@ use Drupal\Core\Database\Schema as DatabaseSchema;
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLite implementation of \Drupal\Core\Database\Schema.
|
||||
*/
|
||||
class Schema extends DatabaseSchema {
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,9 @@ namespace Drupal\Core\Database\Driver\sqlite;
|
|||
|
||||
use Drupal\Core\Database\Query\Select as QuerySelect;
|
||||
|
||||
/**
|
||||
* SQLite implementation of \Drupal\Core\Database\Query\Select.
|
||||
*/
|
||||
class Select extends QuerySelect {
|
||||
public function forUpdate($set = TRUE) {
|
||||
// SQLite does not support FOR UPDATE so nothing to do.
|
||||
|
|
|
@ -11,7 +11,7 @@ use Drupal\Core\Database\StatementPrefetch;
|
|||
use Drupal\Core\Database\StatementInterface;
|
||||
|
||||
/**
|
||||
* Specific SQLite implementation of DatabaseConnection.
|
||||
* SQLite implementation of \Drupal\Core\Database\Statement.
|
||||
*
|
||||
* The PDO SQLite driver only closes SELECT statements when the PDOStatement
|
||||
* destructor is called and SQLite does not allow data change (INSERT,
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\sqlite;
|
|||
|
||||
use Drupal\Core\Database\Transaction as DatabaseTransaction;
|
||||
|
||||
/**
|
||||
* SQLite implementation of \Drupal\Core\Database\Transaction.
|
||||
*/
|
||||
class Transaction extends DatabaseTransaction { }
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Drupal\Core\Database\Driver\sqlite;
|
|||
use Drupal\Core\Database\Query\Truncate as QueryTruncate;
|
||||
|
||||
/**
|
||||
* SQLite specific implementation of TruncateQuery.
|
||||
* SQLite implementation of \Drupal\Core\Database\Query\Truncate.
|
||||
*
|
||||
* SQLite doesn't support TRUNCATE, but a DELETE query with no condition has
|
||||
* exactly the effect (it is implemented by DROPing the table).
|
||||
|
|
|
@ -9,4 +9,7 @@ namespace Drupal\Core\Database\Driver\sqlite;
|
|||
|
||||
use Drupal\Core\Database\Query\Update as QueryUpdate;
|
||||
|
||||
/**
|
||||
* SQLite implementation of \Drupal\Core\Database\Query\Update.
|
||||
*/
|
||||
class Update extends QueryUpdate { }
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Drupal\Core\Database\Driver\sqlite;
|
|||
use Drupal\Core\Database\Query\Upsert as QueryUpsert;
|
||||
|
||||
/**
|
||||
* Implements the Upsert query for the SQLite database driver.
|
||||
* SQLite implementation of \Drupal\Core\Database\Query\Upsert.
|
||||
*/
|
||||
class Upsert extends QueryUpsert {
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class Condition implements ConditionInterface, \Countable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::condition().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function condition($field, $value = NULL, $operator = '=') {
|
||||
if (empty($operator)) {
|
||||
|
@ -88,7 +88,7 @@ class Condition implements ConditionInterface, \Countable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::where().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($snippet, $args = array()) {
|
||||
$this->conditions[] = array(
|
||||
|
@ -102,42 +102,42 @@ class Condition implements ConditionInterface, \Countable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::isNull().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNull($field) {
|
||||
return $this->condition($field, NULL, 'IS NULL');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNotNull($field) {
|
||||
return $this->condition($field, NULL, 'IS NOT NULL');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::exists().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exists(SelectInterface $select) {
|
||||
return $this->condition('', $select, 'EXISTS');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::notExists().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notExists(SelectInterface $select) {
|
||||
return $this->condition('', $select, 'NOT EXISTS');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::conditions().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function &conditions() {
|
||||
return $this->conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::arguments().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function arguments() {
|
||||
// If the caller forgot to call compile() first, refuse to run.
|
||||
|
@ -148,7 +148,7 @@ class Condition implements ConditionInterface, \Countable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::compile().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compile(Connection $connection, PlaceholderInterface $queryPlaceholder) {
|
||||
// Re-compile if this condition changed or if we are compiled against a
|
||||
|
@ -247,7 +247,7 @@ class Condition implements ConditionInterface, \Countable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::compiled().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compiled() {
|
||||
return !$this->changed;
|
||||
|
|
|
@ -47,8 +47,8 @@ class Delete extends Query implements ConditionInterface {
|
|||
/**
|
||||
* Executes the DELETE query.
|
||||
*
|
||||
* @return
|
||||
* The return value is dependent on the database connection.
|
||||
* @return int
|
||||
* The number of rows affected by the delete query.
|
||||
*/
|
||||
public function execute() {
|
||||
$values = array();
|
||||
|
|
|
@ -26,7 +26,7 @@ trait QueryConditionTrait {
|
|||
protected $condition;
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::condition().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function condition($field, $value = NULL, $operator = '=') {
|
||||
$this->condition->condition($field, $value, $operator);
|
||||
|
@ -34,7 +34,7 @@ trait QueryConditionTrait {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::isNull().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNull($field) {
|
||||
$this->condition->isNull($field);
|
||||
|
@ -42,7 +42,7 @@ trait QueryConditionTrait {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::isNotNull().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNotNull($field) {
|
||||
$this->condition->isNotNull($field);
|
||||
|
@ -50,7 +50,7 @@ trait QueryConditionTrait {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::exists().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exists(SelectInterface $select) {
|
||||
$this->condition->exists($select);
|
||||
|
@ -58,7 +58,7 @@ trait QueryConditionTrait {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::notExists().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function notExists(SelectInterface $select) {
|
||||
$this->condition->notExists($select);
|
||||
|
@ -66,21 +66,21 @@ trait QueryConditionTrait {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::conditions().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function &conditions() {
|
||||
return $this->condition->conditions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::arguments().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function arguments() {
|
||||
return $this->condition->arguments();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::where().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function where($snippet, $args = array()) {
|
||||
$this->condition->where($snippet, $args);
|
||||
|
@ -88,35 +88,35 @@ trait QueryConditionTrait {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::compile().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compile(Connection $connection, PlaceholderInterface $queryPlaceholder) {
|
||||
$this->condition->compile($connection, $queryPlaceholder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::compiled().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compiled() {
|
||||
return $this->condition->compiled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::conditionGroupFactory().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function conditionGroupFactory($conjunction = 'AND') {
|
||||
return new Condition($conjunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::andConditionGroup().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function andConditionGroup() {
|
||||
return $this->conditionGroupFactory('AND');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::orConditionGroup().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function orConditionGroup() {
|
||||
return $this->conditionGroupFactory('OR');
|
||||
|
|
|
@ -40,14 +40,14 @@ class Truncate extends Query {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::compile().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compile(Connection $connection, PlaceholderInterface $queryPlaceholder) {
|
||||
return $this->condition->compile($connection, $queryPlaceholder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Core\Database\Query\ConditionInterface::compiled().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compiled() {
|
||||
return $this->condition->compiled();
|
||||
|
|
|
@ -56,14 +56,14 @@ abstract class Schema implements PlaceholderInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements PlaceHolderInterface::uniqueIdentifier().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function uniqueIdentifier() {
|
||||
return $this->uniqueIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements PlaceHolderInterface::nextPlaceholder().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function nextPlaceholder() {
|
||||
return $this->placeholder++;
|
||||
|
|
|
@ -16,7 +16,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
|
|||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* Provides a service to handler various date related functionality.
|
||||
* Provides a service to handle various date related functionality.
|
||||
*
|
||||
* @ingroup i18n
|
||||
*/
|
||||
|
|
|
@ -440,7 +440,7 @@ class DateHelper {
|
|||
* Identifies the number of days in a month for a date.
|
||||
*
|
||||
* @param mixed $date
|
||||
* (optional) A date object, timestamp, or a date string.
|
||||
* (optional) A DrupalDateTime object or a date string.
|
||||
* Defaults to NULL, which means to use the current date.
|
||||
*
|
||||
* @return int
|
||||
|
@ -460,7 +460,7 @@ class DateHelper {
|
|||
* Identifies the number of days in a year for a date.
|
||||
*
|
||||
* @param mixed $date
|
||||
* (optional) A date object, timestamp, or a date string.
|
||||
* (optional) A DrupalDateTime object or a date string.
|
||||
* Defaults to NULL, which means to use the current date.
|
||||
*
|
||||
* @return int
|
||||
|
@ -485,7 +485,7 @@ class DateHelper {
|
|||
* Returns day of week for a given date (0 = Sunday).
|
||||
*
|
||||
* @param mixed $date
|
||||
* (optional) A date object, timestamp, or a date string.
|
||||
* (optional) A DrupalDateTime object or a date string.
|
||||
* Defaults to NULL, which means use the current date.
|
||||
*
|
||||
* @return int
|
||||
|
@ -505,7 +505,7 @@ class DateHelper {
|
|||
* Returns translated name of the day of week for a given date.
|
||||
*
|
||||
* @param mixed $date
|
||||
* (optional) A date object, timestamp, or a date string.
|
||||
* (optional) A DrupalDateTime object or a date string.
|
||||
* Defaults to NULL, which means use the current date.
|
||||
* @param string $abbr
|
||||
* (optional) Whether to return the abbreviated name for that day.
|
||||
|
|
|
@ -36,8 +36,7 @@ class DrupalDateTime extends DateTimePlus {
|
|||
* Constructs a date object.
|
||||
*
|
||||
* @param string $time
|
||||
* A DateTime object, a date/input_time_adjusted string, a unix timestamp.
|
||||
* Defaults to 'now'.
|
||||
* A date/input_time_adjusted string. Defaults to 'now'.
|
||||
* @param mixed $timezone
|
||||
* PHP DateTimeZone object, string or NULL allowed.
|
||||
* Defaults to NULL.
|
||||
|
|
|
@ -20,12 +20,12 @@ interface ClassResolverInterface {
|
|||
* @param string $definition
|
||||
* A class name or service name.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* If $class is not a valid service identifier and the class does not exist.
|
||||
*
|
||||
* @return object
|
||||
* The instance of the class.
|
||||
*/
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* If $class is not a valid service identifier and the class does not exist.
|
||||
*/
|
||||
public function getInstanceFromDefinition($definition);
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|||
class RegisterServicesForDestructionPass implements CompilerPassInterface {
|
||||
|
||||
/**
|
||||
* Implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface::process().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container) {
|
||||
if (!$container->hasDefinition('kernel_destruct_subscriber')) {
|
||||
|
|
|
@ -821,6 +821,13 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
|||
// If there is no container and no cached container definition, build a new
|
||||
// one from scratch.
|
||||
if (!isset($container) && !isset($container_definition)) {
|
||||
if (version_compare(phpversion(), '7.0.0-dev') >= 0) {
|
||||
// The service graph implementation is prone to corruption during GC.
|
||||
// Collect cycles now then disable the GC for the time of the compiler
|
||||
// run.
|
||||
// @see https://bugs.php.net/bug.php?id=70805
|
||||
gc_collect_cycles();
|
||||
}
|
||||
$container = $this->compileContainer();
|
||||
|
||||
// Only dump the container if dumping is allowed. This is useful for
|
||||
|
@ -1386,7 +1393,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
|||
* The request object
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the hostmame is valid, or FALSE otherwise.
|
||||
* TRUE if the hostname is valid, or FALSE otherwise.
|
||||
*/
|
||||
public static function validateHostname(Request $request) {
|
||||
// $request->getHost() can throw an UnexpectedValueException if it
|
||||
|
@ -1412,7 +1419,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
|||
* is possible to create an attack vectors against a site by overriding this.
|
||||
* Symfony provides a mechanism for creating a list of trusted Host values.
|
||||
*
|
||||
* Host patterns (as regular expressions) can be configured throught
|
||||
* Host patterns (as regular expressions) can be configured through
|
||||
* settings.php for multisite installations, sites using ServerAlias without
|
||||
* canonical redirection, or configurations where the site responds to default
|
||||
* requests. For example,
|
||||
|
|
|
@ -166,7 +166,7 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
|
|||
protected $validationRequired = FALSE;
|
||||
|
||||
/**
|
||||
* Overrides Entity::__construct().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $values, $entity_type, $bundle = FALSE, $translations = array()) {
|
||||
$this->entityTypeId = $entity_type;
|
||||
|
@ -998,7 +998,7 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
|
|||
}
|
||||
|
||||
/**
|
||||
* Overrides Entity::createDuplicate().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createDuplicate() {
|
||||
if ($this->translations[$this->activeLangcode]['status'] == static::TRANSLATION_REMOVED) {
|
||||
|
|
|
@ -91,11 +91,11 @@ class EntityRouteEnhancer implements RouteEnhancerInterface {
|
|||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The Request instance.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* Thrown when an entity of a type cannot be found in a route.
|
||||
*
|
||||
* @return array
|
||||
* The modified defaults.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* Thrown when an entity of a type cannot be found in a route.
|
||||
*/
|
||||
protected function enhanceEntityView(array $defaults, Request $request) {
|
||||
$defaults['_controller'] = '\Drupal\Core\Entity\Controller\EntityViewController::view';
|
||||
|
|
|
@ -159,7 +159,7 @@ abstract class Entity implements EntityInterface {
|
|||
*/
|
||||
public function urlInfo($rel = 'canonical', array $options = []) {
|
||||
if ($this->id() === NULL) {
|
||||
throw new EntityMalformedException(sprintf('The "%s" entity cannot have a URI as it does have an ID', $this->getEntityTypeId()));
|
||||
throw new EntityMalformedException(sprintf('The "%s" entity cannot have a URI as it does not have an ID', $this->getEntityTypeId()));
|
||||
}
|
||||
|
||||
// The links array might contain URI templates set in annotations.
|
||||
|
|
|
@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityDisplayPluginCollection;
|
|||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Entity\EntityDisplayBase;
|
||||
use Drupal\Core\TypedData\TranslatableInterface;
|
||||
|
||||
/**
|
||||
* Configuration entity that contains display options for all components of a
|
||||
|
@ -249,7 +250,18 @@ class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayIn
|
|||
$items = $grouped_items[$id];
|
||||
/** @var \Drupal\Core\Access\AccessResultInterface $field_access */
|
||||
$field_access = $items->access('view', NULL, TRUE);
|
||||
$build_list[$id][$name] = $field_access->isAllowed() ? $formatter->view($items, $entity->language()->getId()) : [];
|
||||
// The language of the field values to display is already determined
|
||||
// in the incoming $entity. The formatter should build its output of
|
||||
// those values using:
|
||||
// - the entity language if the entity is translatable,
|
||||
// - the current "content language" otherwise.
|
||||
if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
|
||||
$view_langcode = $entity->language()->getId();
|
||||
}
|
||||
else {
|
||||
$view_langcode = NULL;
|
||||
}
|
||||
$build_list[$id][$name] = $field_access->isAllowed() ? $formatter->view($items, $view_langcode) : [];
|
||||
// Apply the field access cacheability metadata to the render array.
|
||||
$this->renderer->addCacheableDependency($build_list[$id][$name], $field_access);
|
||||
}
|
||||
|
|
|
@ -45,13 +45,13 @@ class EntityAutocompleteMatcher {
|
|||
* @param string $string
|
||||
* (optional) The label of the entity to query by.
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
|
||||
* Thrown when the current user doesn't have access to the specifies entity.
|
||||
*
|
||||
* @return array
|
||||
* An array of matched entity labels, in the format required by the AJAX
|
||||
* autocomplete API (e.g. array('value' => $value, 'label' => $label)).
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
|
||||
* Thrown when the current user doesn't have access to the specified entity.
|
||||
*
|
||||
* @see \Drupal\system\Controller\EntityAutocompleteController
|
||||
*/
|
||||
public function getMatches($target_type, $selection_handler, $selection_settings, $string = '') {
|
||||
|
|
93
core/lib/Drupal/Core/Entity/EntityBundleListener.php
Normal file
93
core/lib/Drupal/Core/Entity/EntityBundleListener.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityBundleListener.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
|
||||
/**
|
||||
* Reacts to entity bundle CRUD on behalf of the Entity system.
|
||||
*/
|
||||
class EntityBundleListener implements EntityBundleListenerInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity type bundle info.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
|
||||
*/
|
||||
protected $entityTypeBundleInfo;
|
||||
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityBundleListener.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
|
||||
* The entity type bundle info.
|
||||
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
|
||||
* The entity field manager.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityFieldManagerInterface $entity_field_manager, ModuleHandlerInterface $module_handler) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->entityTypeBundleInfo = $entity_type_bundle_info;
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onBundleCreate($bundle, $entity_type_id) {
|
||||
$this->entityTypeBundleInfo->clearCachedBundles();
|
||||
// Notify the entity storage.
|
||||
$storage = $this->entityTypeManager->getStorage($entity_type_id);
|
||||
if ($storage instanceof EntityBundleListenerInterface) {
|
||||
$storage->onBundleCreate($bundle, $entity_type_id);
|
||||
}
|
||||
// Invoke hook_entity_bundle_create() hook.
|
||||
$this->moduleHandler->invokeAll('entity_bundle_create', [$entity_type_id, $bundle]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onBundleDelete($bundle, $entity_type_id) {
|
||||
$this->entityTypeBundleInfo->clearCachedBundles();
|
||||
// Notify the entity storage.
|
||||
$storage = $this->entityTypeManager->getStorage($entity_type_id);
|
||||
if ($storage instanceof EntityBundleListenerInterface) {
|
||||
$storage->onBundleDelete($bundle, $entity_type_id);
|
||||
}
|
||||
// Invoke hook_entity_bundle_delete() hook.
|
||||
$this->moduleHandler->invokeAll('entity_bundle_delete', [$entity_type_id, $bundle]);
|
||||
$this->entityFieldManager->clearCachedFieldDefinitions();
|
||||
}
|
||||
|
||||
}
|
251
core/lib/Drupal/Core/Entity/EntityDisplayRepository.php
Normal file
251
core/lib/Drupal/Core/Entity/EntityDisplayRepository.php
Normal file
|
@ -0,0 +1,251 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityDisplayRepository.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Cache\UseCacheBackendTrait;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Provides a repository for entity display objects (view modes and form modes).
|
||||
*/
|
||||
class EntityDisplayRepository implements EntityDisplayRepositoryInterface {
|
||||
|
||||
use UseCacheBackendTrait;
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Static cache of display modes information.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $displayModeInfo = [];
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityDisplayRepository.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* The cache backend.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->cacheBackend = $cache_backend;
|
||||
$this->languageManager = $language_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllViewModes() {
|
||||
return $this->getAllDisplayModesByEntityType('view_mode');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewModes($entity_type_id) {
|
||||
return $this->getDisplayModesByEntityType('view_mode', $entity_type_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllFormModes() {
|
||||
return $this->getAllDisplayModesByEntityType('form_mode');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormModes($entity_type_id) {
|
||||
return $this->getDisplayModesByEntityType('form_mode', $entity_type_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entity display mode info for all entity types.
|
||||
*
|
||||
* @param string $display_type
|
||||
* The display type to be retrieved. It can be "view_mode" or "form_mode".
|
||||
*
|
||||
* @return array
|
||||
* The display mode info for all entity types.
|
||||
*/
|
||||
protected function getAllDisplayModesByEntityType($display_type) {
|
||||
if (!isset($this->displayModeInfo[$display_type])) {
|
||||
$key = 'entity_' . $display_type . '_info';
|
||||
$entity_type_id = 'entity_' . $display_type;
|
||||
$langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_INTERFACE)->getId();
|
||||
if ($cache = $this->cacheGet("$key:$langcode")) {
|
||||
$this->displayModeInfo[$display_type] = $cache->data;
|
||||
}
|
||||
else {
|
||||
$this->displayModeInfo[$display_type] = [];
|
||||
foreach ($this->entityTypeManager->getStorage($entity_type_id)->loadMultiple() as $display_mode) {
|
||||
list($display_mode_entity_type, $display_mode_name) = explode('.', $display_mode->id(), 2);
|
||||
$this->displayModeInfo[$display_type][$display_mode_entity_type][$display_mode_name] = $display_mode->toArray();
|
||||
}
|
||||
$this->moduleHandler->alter($key, $this->displayModeInfo[$display_type]);
|
||||
$this->cacheSet("$key:$langcode", $this->displayModeInfo[$display_type], CacheBackendInterface::CACHE_PERMANENT, ['entity_types', 'entity_field_info']);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->displayModeInfo[$display_type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entity display mode info for a specific entity type.
|
||||
*
|
||||
* @param string $display_type
|
||||
* The display type to be retrieved. It can be "view_mode" or "form_mode".
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose display mode info should be returned.
|
||||
*
|
||||
* @return array
|
||||
* The display mode info for a specific entity type.
|
||||
*/
|
||||
protected function getDisplayModesByEntityType($display_type, $entity_type_id) {
|
||||
if (isset($this->displayModeInfo[$display_type][$entity_type_id])) {
|
||||
return $this->displayModeInfo[$display_type][$entity_type_id];
|
||||
}
|
||||
else {
|
||||
$display_modes = $this->getAllDisplayModesByEntityType($display_type);
|
||||
if (isset($display_modes[$entity_type_id])) {
|
||||
return $display_modes[$entity_type_id];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewModeOptions($entity_type) {
|
||||
return $this->getDisplayModeOptions('view_mode', $entity_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormModeOptions($entity_type_id) {
|
||||
return $this->getDisplayModeOptions('form_mode', $entity_type_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewModeOptionsByBundle($entity_type_id, $bundle) {
|
||||
return $this->getDisplayModeOptionsByBundle('view_mode', $entity_type_id, $bundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormModeOptionsByBundle($entity_type_id, $bundle) {
|
||||
return $this->getDisplayModeOptionsByBundle('form_mode', $entity_type_id, $bundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of display mode options.
|
||||
*
|
||||
* @param string $display_type
|
||||
* The display type to be retrieved. It can be "view_mode" or "form_mode".
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose display mode options should be returned.
|
||||
*
|
||||
* @return array
|
||||
* An array of display mode labels, keyed by the display mode ID.
|
||||
*/
|
||||
protected function getDisplayModeOptions($display_type, $entity_type_id) {
|
||||
$options = array('default' => t('Default'));
|
||||
foreach ($this->getDisplayModesByEntityType($display_type, $entity_type_id) as $mode => $settings) {
|
||||
$options[$mode] = $settings['label'];
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of enabled display mode options by bundle.
|
||||
*
|
||||
* @param $display_type
|
||||
* The display type to be retrieved. It can be "view_mode" or "form_mode".
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose display mode options should be returned.
|
||||
* @param string $bundle
|
||||
* The name of the bundle.
|
||||
*
|
||||
* @return array
|
||||
* An array of display mode labels, keyed by the display mode ID.
|
||||
*/
|
||||
protected function getDisplayModeOptionsByBundle($display_type, $entity_type_id, $bundle) {
|
||||
// Collect all the entity's display modes.
|
||||
$options = $this->getDisplayModeOptions($display_type, $entity_type_id);
|
||||
|
||||
// Filter out modes for which the entity display is disabled
|
||||
// (or non-existent).
|
||||
$load_ids = array();
|
||||
// Get the list of available entity displays for the current bundle.
|
||||
foreach (array_keys($options) as $mode) {
|
||||
$load_ids[] = $entity_type_id . '.' . $bundle . '.' . $mode;
|
||||
}
|
||||
|
||||
// Load the corresponding displays.
|
||||
$displays = $this->entityTypeManager
|
||||
->getStorage($display_type == 'form_mode' ? 'entity_form_display' : 'entity_view_display')
|
||||
->loadMultiple($load_ids);
|
||||
|
||||
// Unset the display modes that are not active or do not exist.
|
||||
foreach (array_keys($options) as $mode) {
|
||||
$display_id = $entity_type_id . '.' . $bundle . '.' . $mode;
|
||||
if (!isset($displays[$display_id]) || !$displays[$display_id]->status()) {
|
||||
unset($options[$mode]);
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearDisplayModeInfo() {
|
||||
$this->displayModeInfo = [];
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
108
core/lib/Drupal/Core/Entity/EntityDisplayRepositoryInterface.php
Normal file
108
core/lib/Drupal/Core/Entity/EntityDisplayRepositoryInterface.php
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityDisplayRepositoryInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
/**
|
||||
* Provides an interface for an entity display repository.
|
||||
*/
|
||||
interface EntityDisplayRepositoryInterface {
|
||||
|
||||
/**
|
||||
* Gets the entity view mode info for all entity types.
|
||||
*
|
||||
* @return array
|
||||
* The view mode info for all entity types.
|
||||
*/
|
||||
public function getAllViewModes();
|
||||
|
||||
/**
|
||||
* Gets the entity view mode info for a specific entity type.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose view mode info should be returned.
|
||||
*
|
||||
* @return array
|
||||
* The view mode info for a specific entity type.
|
||||
*/
|
||||
public function getViewModes($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets the entity form mode info for all entity types.
|
||||
*
|
||||
* @return array
|
||||
* The form mode info for all entity types.
|
||||
*/
|
||||
public function getAllFormModes();
|
||||
|
||||
/**
|
||||
* Gets the entity form mode info for a specific entity type.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose form mode info should be returned.
|
||||
*
|
||||
* @return array
|
||||
* The form mode info for a specific entity type.
|
||||
*/
|
||||
public function getFormModes($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets an array of view mode options.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose view mode options should be returned.
|
||||
*
|
||||
* @return array
|
||||
* An array of view mode labels, keyed by the display mode ID.
|
||||
*/
|
||||
public function getViewModeOptions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets an array of form mode options.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose form mode options should be returned.
|
||||
*
|
||||
* @return array
|
||||
* An array of form mode labels, keyed by the display mode ID.
|
||||
*/
|
||||
public function getFormModeOptions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Returns an array of enabled view mode options by bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose view mode options should be returned.
|
||||
* @param string $bundle
|
||||
* The name of the bundle.
|
||||
*
|
||||
* @return array
|
||||
* An array of view mode labels, keyed by the display mode ID.
|
||||
*/
|
||||
public function getViewModeOptionsByBundle($entity_type_id, $bundle);
|
||||
|
||||
/**
|
||||
* Returns an array of enabled form mode options by bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose form mode options should be returned.
|
||||
* @param string $bundle
|
||||
* The name of the bundle.
|
||||
*
|
||||
* @return array
|
||||
* An array of form mode labels, keyed by the display mode ID.
|
||||
*/
|
||||
public function getFormModeOptionsByBundle($entity_type_id, $bundle);
|
||||
|
||||
/**
|
||||
* Clears the gathered display mode info.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function clearDisplayModeInfo();
|
||||
|
||||
}
|
601
core/lib/Drupal/Core/Entity/EntityFieldManager.php
Normal file
601
core/lib/Drupal/Core/Entity/EntityFieldManager.php
Normal file
|
@ -0,0 +1,601 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityFieldManager.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Cache\UseCacheBackendTrait;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Core\TypedData\TypedDataManagerInterface;
|
||||
|
||||
/**
|
||||
* Manages the discovery of entity fields.
|
||||
*
|
||||
* This includes field definitions, base field definitions, and field storage
|
||||
* definitions.
|
||||
*/
|
||||
class EntityFieldManager implements EntityFieldManagerInterface {
|
||||
|
||||
use UseCacheBackendTrait;
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Extra fields by bundle.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $extraFields = [];
|
||||
|
||||
/**
|
||||
* Static cache of base field definitions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $baseFieldDefinitions;
|
||||
|
||||
/**
|
||||
* Static cache of field definitions per bundle and entity type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldDefinitions;
|
||||
|
||||
/**
|
||||
* Static cache of field storage definitions per entity type.
|
||||
*
|
||||
* Elements of the array:
|
||||
* - $entity_type_id: \Drupal\Core\Field\BaseFieldDefinition[]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldStorageDefinitions;
|
||||
|
||||
/**
|
||||
* An array keyed by entity type. Each value is an array whose keys are
|
||||
* field names and whose value is an array with two entries:
|
||||
* - type: The field type.
|
||||
* - bundles: The bundles in which the field appears.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected $fieldMap = [];
|
||||
|
||||
/**
|
||||
* An array keyed by field type. Each value is an array whose key are entity
|
||||
* types including arrays in the same form that $fieldMap.
|
||||
*
|
||||
* It helps access the mapping between types and fields by the field type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldMapByFieldType = [];
|
||||
|
||||
/**
|
||||
* The typed data manager.
|
||||
*
|
||||
* @var \Drupal\Core\TypedData\TypedDataManagerInterface
|
||||
*/
|
||||
protected $typedDataManager;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The key-value factory.
|
||||
*
|
||||
* @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface
|
||||
*/
|
||||
protected $keyValueFactory;
|
||||
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity type bundle info.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
|
||||
*/
|
||||
protected $entityTypeBundleInfo;
|
||||
|
||||
/**
|
||||
* The entity display repository.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
|
||||
*/
|
||||
protected $entityDisplayRepository;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityFieldManager.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
|
||||
* The entity type bundle info.
|
||||
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
|
||||
* The entity display repository.
|
||||
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
|
||||
* The typed data manager.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
* @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory
|
||||
* The key-value factory.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* The cache backend.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityDisplayRepositoryInterface $entity_display_repository, TypedDataManagerInterface $typed_data_manager, LanguageManagerInterface $language_manager, KeyValueFactoryInterface $key_value_factory, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->entityTypeBundleInfo = $entity_type_bundle_info;
|
||||
$this->entityDisplayRepository = $entity_display_repository;
|
||||
|
||||
$this->typedDataManager = $typed_data_manager;
|
||||
$this->languageManager = $language_manager;
|
||||
$this->keyValueFactory = $key_value_factory;
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->cacheBackend = $cache_backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBaseFieldDefinitions($entity_type_id) {
|
||||
// Check the static cache.
|
||||
if (!isset($this->baseFieldDefinitions[$entity_type_id])) {
|
||||
// Not prepared, try to load from cache.
|
||||
$cid = 'entity_base_field_definitions:' . $entity_type_id . ':' . $this->languageManager->getCurrentLanguage()->getId();
|
||||
if ($cache = $this->cacheGet($cid)) {
|
||||
$this->baseFieldDefinitions[$entity_type_id] = $cache->data;
|
||||
}
|
||||
else {
|
||||
// Rebuild the definitions and put it into the cache.
|
||||
$this->baseFieldDefinitions[$entity_type_id] = $this->buildBaseFieldDefinitions($entity_type_id);
|
||||
$this->cacheSet($cid, $this->baseFieldDefinitions[$entity_type_id], Cache::PERMANENT, ['entity_types', 'entity_field_info']);
|
||||
}
|
||||
}
|
||||
return $this->baseFieldDefinitions[$entity_type_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds base field definitions for an entity type.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID. Only entity types that implement
|
||||
* \Drupal\Core\Entity\FieldableEntityInterface are supported.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldDefinitionInterface[]
|
||||
* An array of field definitions, keyed by field name.
|
||||
*
|
||||
* @throws \LogicException
|
||||
* Thrown if a config entity type is given or if one of the entity keys is
|
||||
* flagged as translatable.
|
||||
*/
|
||||
protected function buildBaseFieldDefinitions($entity_type_id) {
|
||||
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
|
||||
$class = $entity_type->getClass();
|
||||
$keys = array_filter($entity_type->getKeys());
|
||||
|
||||
// Fail with an exception for non-fieldable entity types.
|
||||
if (!$entity_type->isSubclassOf(FieldableEntityInterface::class)) {
|
||||
throw new \LogicException("Getting the base fields is not supported for entity type {$entity_type->getLabel()}.");
|
||||
}
|
||||
|
||||
// Retrieve base field definitions.
|
||||
/** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $base_field_definitions */
|
||||
$base_field_definitions = $class::baseFieldDefinitions($entity_type);
|
||||
|
||||
// Make sure translatable entity types are correctly defined.
|
||||
if ($entity_type->isTranslatable()) {
|
||||
// The langcode field should always be translatable if the entity type is.
|
||||
if (isset($keys['langcode']) && isset($base_field_definitions[$keys['langcode']])) {
|
||||
$base_field_definitions[$keys['langcode']]->setTranslatable(TRUE);
|
||||
}
|
||||
// A default_langcode field should always be defined.
|
||||
if (!isset($base_field_definitions[$keys['default_langcode']])) {
|
||||
$base_field_definitions[$keys['default_langcode']] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel($this->t('Default translation'))
|
||||
->setDescription($this->t('A flag indicating whether this is the default translation.'))
|
||||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE)
|
||||
->setDefaultValue(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
// Assign base field definitions the entity type provider.
|
||||
$provider = $entity_type->getProvider();
|
||||
foreach ($base_field_definitions as $definition) {
|
||||
// @todo Remove this check once FieldDefinitionInterface exposes a proper
|
||||
// provider setter. See https://www.drupal.org/node/2225961.
|
||||
if ($definition instanceof BaseFieldDefinition) {
|
||||
$definition->setProvider($provider);
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve base field definitions from modules.
|
||||
foreach ($this->moduleHandler->getImplementations('entity_base_field_info') as $module) {
|
||||
$module_definitions = $this->moduleHandler->invoke($module, 'entity_base_field_info', [$entity_type]);
|
||||
if (!empty($module_definitions)) {
|
||||
// Ensure the provider key actually matches the name of the provider
|
||||
// defining the field.
|
||||
foreach ($module_definitions as $field_name => $definition) {
|
||||
// @todo Remove this check once FieldDefinitionInterface exposes a
|
||||
// proper provider setter. See https://www.drupal.org/node/2225961.
|
||||
if ($definition instanceof BaseFieldDefinition && $definition->getProvider() == NULL) {
|
||||
$definition->setProvider($module);
|
||||
}
|
||||
$base_field_definitions[$field_name] = $definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Automatically set the field name, target entity type and bundle
|
||||
// for non-configurable fields.
|
||||
foreach ($base_field_definitions as $field_name => $base_field_definition) {
|
||||
if ($base_field_definition instanceof BaseFieldDefinition) {
|
||||
$base_field_definition->setName($field_name);
|
||||
$base_field_definition->setTargetEntityTypeId($entity_type_id);
|
||||
$base_field_definition->setTargetBundle(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke alter hook.
|
||||
$this->moduleHandler->alter('entity_base_field_info', $base_field_definitions, $entity_type);
|
||||
|
||||
// Ensure defined entity keys are there and have proper revisionable and
|
||||
// translatable values.
|
||||
foreach (array_intersect_key($keys, array_flip(['id', 'revision', 'uuid', 'bundle'])) as $key => $field_name) {
|
||||
if (!isset($base_field_definitions[$field_name])) {
|
||||
throw new \LogicException("The $field_name field definition does not exist and it is used as $key entity key.");
|
||||
}
|
||||
if ($base_field_definitions[$field_name]->isRevisionable()) {
|
||||
throw new \LogicException("The {$base_field_definitions[$field_name]->getLabel()} field cannot be revisionable as it is used as $key entity key.");
|
||||
}
|
||||
if ($base_field_definitions[$field_name]->isTranslatable()) {
|
||||
throw new \LogicException("The {$base_field_definitions[$field_name]->getLabel()} field cannot be translatable as it is used as $key entity key.");
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure translatable entity types define the "langcode" field properly.
|
||||
if ($entity_type->isTranslatable() && (!isset($keys['langcode']) || !isset($base_field_definitions[$keys['langcode']]) || !$base_field_definitions[$keys['langcode']]->isTranslatable())) {
|
||||
throw new \LogicException("The {$entity_type->getLabel()} entity type cannot be translatable as it does not define a translatable \"langcode\" field.");
|
||||
}
|
||||
|
||||
return $base_field_definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldDefinitions($entity_type_id, $bundle) {
|
||||
if (!isset($this->fieldDefinitions[$entity_type_id][$bundle])) {
|
||||
$base_field_definitions = $this->getBaseFieldDefinitions($entity_type_id);
|
||||
// Not prepared, try to load from cache.
|
||||
$cid = 'entity_bundle_field_definitions:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager->getCurrentLanguage()->getId();
|
||||
if ($cache = $this->cacheGet($cid)) {
|
||||
$bundle_field_definitions = $cache->data;
|
||||
}
|
||||
else {
|
||||
// Rebuild the definitions and put it into the cache.
|
||||
$bundle_field_definitions = $this->buildBundleFieldDefinitions($entity_type_id, $bundle, $base_field_definitions);
|
||||
$this->cacheSet($cid, $bundle_field_definitions, Cache::PERMANENT, ['entity_types', 'entity_field_info']);
|
||||
}
|
||||
// Field definitions consist of the bundle specific overrides and the
|
||||
// base fields, merge them together. Use array_replace() to replace base
|
||||
// fields with by bundle overrides and keep them in order, append
|
||||
// additional by bundle fields.
|
||||
$this->fieldDefinitions[$entity_type_id][$bundle] = array_replace($base_field_definitions, $bundle_field_definitions);
|
||||
}
|
||||
return $this->fieldDefinitions[$entity_type_id][$bundle];
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds field definitions for a specific bundle within an entity type.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID. Only entity types that implement
|
||||
* \Drupal\Core\Entity\FieldableEntityInterface are supported.
|
||||
* @param string $bundle
|
||||
* The bundle.
|
||||
* @param \Drupal\Core\Field\FieldDefinitionInterface[] $base_field_definitions
|
||||
* The list of base field definitions.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldDefinitionInterface[]
|
||||
* An array of bundle field definitions, keyed by field name. Does
|
||||
* not include base fields.
|
||||
*/
|
||||
protected function buildBundleFieldDefinitions($entity_type_id, $bundle, array $base_field_definitions) {
|
||||
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
|
||||
$class = $entity_type->getClass();
|
||||
|
||||
// Allow the entity class to provide bundle fields and bundle-specific
|
||||
// overrides of base fields.
|
||||
$bundle_field_definitions = $class::bundleFieldDefinitions($entity_type, $bundle, $base_field_definitions);
|
||||
|
||||
// Load base field overrides from configuration. These take precedence over
|
||||
// base field overrides returned above.
|
||||
$base_field_override_ids = array_map(function($field_name) use ($entity_type_id, $bundle) {
|
||||
return $entity_type_id . '.' . $bundle . '.' . $field_name;
|
||||
}, array_keys($base_field_definitions));
|
||||
$base_field_overrides = $this->entityTypeManager->getStorage('base_field_override')->loadMultiple($base_field_override_ids);
|
||||
foreach ($base_field_overrides as $base_field_override) {
|
||||
/** @var \Drupal\Core\Field\Entity\BaseFieldOverride $base_field_override */
|
||||
$field_name = $base_field_override->getName();
|
||||
$bundle_field_definitions[$field_name] = $base_field_override;
|
||||
}
|
||||
|
||||
$provider = $entity_type->getProvider();
|
||||
foreach ($bundle_field_definitions as $definition) {
|
||||
// @todo Remove this check once FieldDefinitionInterface exposes a proper
|
||||
// provider setter. See https://www.drupal.org/node/2225961.
|
||||
if ($definition instanceof BaseFieldDefinition) {
|
||||
$definition->setProvider($provider);
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve base field definitions from modules.
|
||||
foreach ($this->moduleHandler->getImplementations('entity_bundle_field_info') as $module) {
|
||||
$module_definitions = $this->moduleHandler->invoke($module, 'entity_bundle_field_info', [$entity_type, $bundle, $base_field_definitions]);
|
||||
if (!empty($module_definitions)) {
|
||||
// Ensure the provider key actually matches the name of the provider
|
||||
// defining the field.
|
||||
foreach ($module_definitions as $field_name => $definition) {
|
||||
// @todo Remove this check once FieldDefinitionInterface exposes a
|
||||
// proper provider setter. See https://www.drupal.org/node/2225961.
|
||||
if ($definition instanceof BaseFieldDefinition) {
|
||||
$definition->setProvider($module);
|
||||
}
|
||||
$bundle_field_definitions[$field_name] = $definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Automatically set the field name, target entity type and bundle
|
||||
// for non-configurable fields.
|
||||
foreach ($bundle_field_definitions as $field_name => $field_definition) {
|
||||
if ($field_definition instanceof BaseFieldDefinition) {
|
||||
$field_definition->setName($field_name);
|
||||
$field_definition->setTargetEntityTypeId($entity_type_id);
|
||||
$field_definition->setTargetBundle($bundle);
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke 'per bundle' alter hook.
|
||||
$this->moduleHandler->alter('entity_bundle_field_info', $bundle_field_definitions, $entity_type, $bundle);
|
||||
|
||||
return $bundle_field_definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldStorageDefinitions($entity_type_id) {
|
||||
if (!isset($this->fieldStorageDefinitions[$entity_type_id])) {
|
||||
$this->fieldStorageDefinitions[$entity_type_id] = [];
|
||||
// Add all non-computed base fields.
|
||||
foreach ($this->getBaseFieldDefinitions($entity_type_id) as $field_name => $definition) {
|
||||
if (!$definition->isComputed()) {
|
||||
$this->fieldStorageDefinitions[$entity_type_id][$field_name] = $definition;
|
||||
}
|
||||
}
|
||||
// Not prepared, try to load from cache.
|
||||
$cid = 'entity_field_storage_definitions:' . $entity_type_id . ':' . $this->languageManager->getCurrentLanguage()->getId();
|
||||
if ($cache = $this->cacheGet($cid)) {
|
||||
$field_storage_definitions = $cache->data;
|
||||
}
|
||||
else {
|
||||
// Rebuild the definitions and put it into the cache.
|
||||
$field_storage_definitions = $this->buildFieldStorageDefinitions($entity_type_id);
|
||||
$this->cacheSet($cid, $field_storage_definitions, Cache::PERMANENT, ['entity_types', 'entity_field_info']);
|
||||
}
|
||||
$this->fieldStorageDefinitions[$entity_type_id] += $field_storage_definitions;
|
||||
}
|
||||
return $this->fieldStorageDefinitions[$entity_type_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setFieldMap(array $field_map) {
|
||||
$this->fieldMap = $field_map;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldMap() {
|
||||
if (!$this->fieldMap) {
|
||||
// Not prepared, try to load from cache.
|
||||
$cid = 'entity_field_map';
|
||||
if ($cache = $this->cacheGet($cid)) {
|
||||
$this->fieldMap = $cache->data;
|
||||
}
|
||||
else {
|
||||
// The field map is built in two steps. First, add all base fields, by
|
||||
// looping over all fieldable entity types. They always exist for all
|
||||
// bundles, and we do not expect to have so many different entity
|
||||
// types for this to become a bottleneck.
|
||||
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->isSubclassOf(FieldableEntityInterface::class)) {
|
||||
$bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id));
|
||||
foreach ($this->getBaseFieldDefinitions($entity_type_id) as $field_name => $base_field_definition) {
|
||||
$this->fieldMap[$entity_type_id][$field_name] = [
|
||||
'type' => $base_field_definition->getType(),
|
||||
'bundles' => array_combine($bundles, $bundles),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// In the second step, the per-bundle fields are added, based on the
|
||||
// persistent bundle field map stored in a key value collection. This
|
||||
// data is managed in the EntityManager::onFieldDefinitionCreate()
|
||||
// and EntityManager::onFieldDefinitionDelete() methods. Rebuilding this
|
||||
// information in the same way as base fields would not scale, as the
|
||||
// time to query would grow exponentially with more fields and bundles.
|
||||
// A cache would be deleted during cache clears, which is the only time
|
||||
// it is needed, so a key value collection is used.
|
||||
$bundle_field_maps = $this->keyValueFactory->get('entity.definitions.bundle_field_map')->getAll();
|
||||
foreach ($bundle_field_maps as $entity_type_id => $bundle_field_map) {
|
||||
foreach ($bundle_field_map as $field_name => $map_entry) {
|
||||
if (!isset($this->fieldMap[$entity_type_id][$field_name])) {
|
||||
$this->fieldMap[$entity_type_id][$field_name] = $map_entry;
|
||||
}
|
||||
else {
|
||||
$this->fieldMap[$entity_type_id][$field_name]['bundles'] += $map_entry['bundles'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->cacheSet($cid, $this->fieldMap, Cache::PERMANENT, ['entity_types']);
|
||||
}
|
||||
}
|
||||
return $this->fieldMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldMapByFieldType($field_type) {
|
||||
if (!isset($this->fieldMapByFieldType[$field_type])) {
|
||||
$filtered_map = [];
|
||||
$map = $this->getFieldMap();
|
||||
foreach ($map as $entity_type => $fields) {
|
||||
foreach ($fields as $field_name => $field_info) {
|
||||
if ($field_info['type'] == $field_type) {
|
||||
$filtered_map[$entity_type][$field_name] = $field_info;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->fieldMapByFieldType[$field_type] = $filtered_map;
|
||||
}
|
||||
return $this->fieldMapByFieldType[$field_type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds field storage definitions for an entity type.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID. Only entity types that implement
|
||||
* \Drupal\Core\Entity\FieldableEntityInterface are supported
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldStorageDefinitionInterface[]
|
||||
* An array of field storage definitions, keyed by field name.
|
||||
*/
|
||||
protected function buildFieldStorageDefinitions($entity_type_id) {
|
||||
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
|
||||
$field_definitions = [];
|
||||
|
||||
// Retrieve base field definitions from modules.
|
||||
foreach ($this->moduleHandler->getImplementations('entity_field_storage_info') as $module) {
|
||||
$module_definitions = $this->moduleHandler->invoke($module, 'entity_field_storage_info', [$entity_type]);
|
||||
if (!empty($module_definitions)) {
|
||||
// Ensure the provider key actually matches the name of the provider
|
||||
// defining the field.
|
||||
foreach ($module_definitions as $field_name => $definition) {
|
||||
// @todo Remove this check once FieldDefinitionInterface exposes a
|
||||
// proper provider setter. See https://www.drupal.org/node/2225961.
|
||||
if ($definition instanceof BaseFieldDefinition) {
|
||||
$definition->setProvider($module);
|
||||
}
|
||||
$field_definitions[$field_name] = $definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke alter hook.
|
||||
$this->moduleHandler->alter('entity_field_storage_info', $field_definitions, $entity_type);
|
||||
|
||||
return $field_definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearCachedFieldDefinitions() {
|
||||
$this->baseFieldDefinitions = [];
|
||||
$this->fieldDefinitions = [];
|
||||
$this->fieldStorageDefinitions = [];
|
||||
$this->fieldMap = [];
|
||||
$this->fieldMapByFieldType = [];
|
||||
$this->entityDisplayRepository->clearDisplayModeInfo();
|
||||
$this->extraFields = [];
|
||||
Cache::invalidateTags(['entity_field_info']);
|
||||
// The typed data manager statically caches prototype objects with injected
|
||||
// definitions, clear those as well.
|
||||
$this->typedDataManager->clearCachedDefinitions();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function useCaches($use_caches = FALSE) {
|
||||
$this->useCaches = $use_caches;
|
||||
if (!$use_caches) {
|
||||
$this->fieldDefinitions = [];
|
||||
$this->baseFieldDefinitions = [];
|
||||
$this->fieldStorageDefinitions = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getExtraFields($entity_type_id, $bundle) {
|
||||
// Read from the "static" cache.
|
||||
if (isset($this->extraFields[$entity_type_id][$bundle])) {
|
||||
return $this->extraFields[$entity_type_id][$bundle];
|
||||
}
|
||||
|
||||
// Read from the persistent cache. Since hook_entity_extra_field_info() and
|
||||
// hook_entity_extra_field_info_alter() might contain t() calls, we cache
|
||||
// per language.
|
||||
$cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager->getCurrentLanguage()->getId();
|
||||
$cached = $this->cacheGet($cache_id);
|
||||
if ($cached) {
|
||||
$this->extraFields[$entity_type_id][$bundle] = $cached->data;
|
||||
return $this->extraFields[$entity_type_id][$bundle];
|
||||
}
|
||||
|
||||
$extra = $this->moduleHandler->invokeAll('entity_extra_field_info');
|
||||
$this->moduleHandler->alter('entity_extra_field_info', $extra);
|
||||
$info = isset($extra[$entity_type_id][$bundle]) ? $extra[$entity_type_id][$bundle] : [];
|
||||
$info += [
|
||||
'form' => [],
|
||||
'display' => [],
|
||||
];
|
||||
|
||||
// Store in the 'static' and persistent caches.
|
||||
$this->extraFields[$entity_type_id][$bundle] = $info;
|
||||
$this->cacheSet($cache_id, $info, Cache::PERMANENT, [
|
||||
'entity_field_info',
|
||||
]);
|
||||
|
||||
return $this->extraFields[$entity_type_id][$bundle];
|
||||
}
|
||||
|
||||
}
|
150
core/lib/Drupal/Core/Entity/EntityFieldManagerInterface.php
Normal file
150
core/lib/Drupal/Core/Entity/EntityFieldManagerInterface.php
Normal file
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityFieldManagerInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
/**
|
||||
* Provides an interface for an entity field manager.
|
||||
*/
|
||||
interface EntityFieldManagerInterface {
|
||||
|
||||
/**
|
||||
* Gets the base field definitions for a content entity type.
|
||||
*
|
||||
* Only fields that are not specific to a given bundle or set of bundles are
|
||||
* returned. This excludes configurable fields, as they are always attached
|
||||
* to a specific bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID. Only entity types that implement
|
||||
* \Drupal\Core\Entity\FieldableEntityInterface are supported.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldDefinitionInterface[]
|
||||
* The array of base field definitions for the entity type, keyed by field
|
||||
* name.
|
||||
*
|
||||
* @throws \LogicException
|
||||
* Thrown if one of the entity keys is flagged as translatable.
|
||||
*/
|
||||
public function getBaseFieldDefinitions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets the field definitions for a specific bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID. Only entity types that implement
|
||||
* \Drupal\Core\Entity\FieldableEntityInterface are supported.
|
||||
* @param string $bundle
|
||||
* The bundle.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldDefinitionInterface[]
|
||||
* The array of field definitions for the bundle, keyed by field name.
|
||||
*/
|
||||
public function getFieldDefinitions($entity_type_id, $bundle);
|
||||
|
||||
/**
|
||||
* Gets the field storage definitions for a content entity type.
|
||||
*
|
||||
* This returns all field storage definitions for base fields and bundle
|
||||
* fields of an entity type. Note that field storage definitions of a base
|
||||
* field equal the full base field definition (i.e. they implement
|
||||
* FieldDefinitionInterface), while the storage definitions for bundle fields
|
||||
* may implement FieldStorageDefinitionInterface only.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID. Only content entities are supported.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldStorageDefinitionInterface[]
|
||||
* The array of field storage definitions for the entity type, keyed by
|
||||
* field name.
|
||||
*
|
||||
* @see \Drupal\Core\Field\FieldStorageDefinitionInterface
|
||||
*/
|
||||
public function getFieldStorageDefinitions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets a lightweight map of fields across bundles.
|
||||
*
|
||||
* @return array
|
||||
* An array keyed by entity type. Each value is an array which keys are
|
||||
* field names and value is an array with two entries:
|
||||
* - type: The field type.
|
||||
* - bundles: The bundles in which the field appears.
|
||||
*/
|
||||
public function getFieldMap();
|
||||
|
||||
/**
|
||||
* Sets a lightweight map of fields across bundles.
|
||||
*
|
||||
* @param array[] $field_map
|
||||
* See the return value of self::getFieldMap().
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFieldMap(array $field_map);
|
||||
|
||||
/**
|
||||
* Gets a lightweight map of fields across bundles filtered by field type.
|
||||
*
|
||||
* @param string $field_type
|
||||
* The field type to filter by.
|
||||
*
|
||||
* @return array
|
||||
* An array keyed by entity type. Each value is an array which keys are
|
||||
* field names and value is an array with two entries:
|
||||
* - type: The field type.
|
||||
* - bundles: The bundles in which the field appears.
|
||||
*/
|
||||
public function getFieldMapByFieldType($field_type);
|
||||
|
||||
/**
|
||||
* Clears static and persistent field definition caches.
|
||||
*/
|
||||
public function clearCachedFieldDefinitions();
|
||||
|
||||
/**
|
||||
* Disable the use of caches.
|
||||
*
|
||||
* @param bool $use_caches
|
||||
* FALSE to not use any caches.
|
||||
*
|
||||
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
||||
*
|
||||
* @todo Remove in https://www.drupal.org/node/2549143.
|
||||
*/
|
||||
public function useCaches($use_caches = FALSE);
|
||||
|
||||
/**
|
||||
* Gets the "extra fields" for a bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID.
|
||||
* @param string $bundle
|
||||
* The bundle name.
|
||||
*
|
||||
* @return array
|
||||
* A nested array of 'pseudo-field' elements. Each list is nested within the
|
||||
* following keys: entity type, bundle name, context (either 'form' or
|
||||
* 'display'). The keys are the name of the elements as appearing in the
|
||||
* renderable array (either the entity form or the displayed entity). The
|
||||
* value is an associative array:
|
||||
* - label: The human readable name of the element. Make sure you sanitize
|
||||
* this appropriately.
|
||||
* - description: A short description of the element contents.
|
||||
* - weight: The default weight of the element.
|
||||
* - visible: (optional) The default visibility of the element. Defaults to
|
||||
* TRUE.
|
||||
* - edit: (optional) String containing markup (normally a link) used as the
|
||||
* element's 'edit' operation in the administration interface. Only for
|
||||
* 'form' context.
|
||||
* - delete: (optional) String containing markup (normally a link) used as the
|
||||
* element's 'delete' operation in the administration interface. Only for
|
||||
* 'form' context.
|
||||
*/
|
||||
public function getExtraFields($entity_type_id, $bundle);
|
||||
|
||||
}
|
|
@ -41,9 +41,18 @@ class EntityForm extends FormBase implements EntityFormInterface {
|
|||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*
|
||||
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity being used by this form.
|
||||
*
|
||||
|
@ -404,4 +413,12 @@ class EntityForm extends FormBase implements EntityFormInterface {
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -137,7 +137,21 @@ interface EntityFormInterface extends BaseFormIdInterface {
|
|||
* The entity manager.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
||||
*
|
||||
* @todo Remove this set call in https://www.drupal.org/node/2603542.
|
||||
*/
|
||||
public function setEntityManager(EntityManagerInterface $entity_manager);
|
||||
|
||||
/**
|
||||
* Sets the entity type manager for this form.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityLastInstalledSchemaRepository.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
|
||||
|
||||
/**
|
||||
* Provides a repository for installed entity definitions.
|
||||
*/
|
||||
class EntityLastInstalledSchemaRepository implements EntityLastInstalledSchemaRepositoryInterface {
|
||||
|
||||
/**
|
||||
* The key-value factory.
|
||||
*
|
||||
* @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface
|
||||
*/
|
||||
protected $keyValueFactory;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityLastInstalledSchemaRepository.
|
||||
*
|
||||
* @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory
|
||||
* The key-value factory.
|
||||
*/
|
||||
public function __construct(KeyValueFactoryInterface $key_value_factory) {
|
||||
$this->keyValueFactory = $key_value_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLastInstalledDefinition($entity_type_id) {
|
||||
return $this->keyValueFactory->get('entity.definitions.installed')->get($entity_type_id . '.entity_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setLastInstalledDefinition(EntityTypeInterface $entity_type) {
|
||||
$entity_type_id = $entity_type->id();
|
||||
$this->keyValueFactory->get('entity.definitions.installed')->set($entity_type_id . '.entity_type', $entity_type);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteLastInstalledDefinition($entity_type_id) {
|
||||
$this->keyValueFactory->get('entity.definitions.installed')->delete($entity_type_id . '.entity_type');
|
||||
// Clean up field storage definitions as well. Even if the entity type
|
||||
// isn't currently fieldable, there might be legacy definitions or an
|
||||
// empty array stored from when it was.
|
||||
$this->keyValueFactory->get('entity.definitions.installed')->delete($entity_type_id . '.field_storage_definitions');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLastInstalledFieldStorageDefinitions($entity_type_id) {
|
||||
return $this->keyValueFactory->get('entity.definitions.installed')->get($entity_type_id . '.field_storage_definitions', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setLastInstalledFieldStorageDefinitions($entity_type_id, array $storage_definitions) {
|
||||
$this->keyValueFactory->get('entity.definitions.installed')->set($entity_type_id . '.field_storage_definitions', $storage_definitions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setLastInstalledFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition) {
|
||||
$entity_type_id = $storage_definition->getTargetEntityTypeId();
|
||||
$definitions = $this->getLastInstalledFieldStorageDefinitions($entity_type_id);
|
||||
$definitions[$storage_definition->getName()] = $storage_definition;
|
||||
$this->setLastInstalledFieldStorageDefinitions($entity_type_id, $definitions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteLastInstalledFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition) {
|
||||
$entity_type_id = $storage_definition->getTargetEntityTypeId();
|
||||
$definitions = $this->getLastInstalledFieldStorageDefinitions($entity_type_id);
|
||||
unset($definitions[$storage_definition->getName()]);
|
||||
$this->setLastInstalledFieldStorageDefinitions($entity_type_id, $definitions);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for an installed entity definition repository.
|
||||
*/
|
||||
interface EntityLastInstalledSchemaRepositoryInterface {
|
||||
|
||||
/**
|
||||
* Gets the entity type definition in its most recently installed state.
|
||||
*
|
||||
* During the application lifetime, entity type definitions can change. For
|
||||
* example, updated code can be deployed. The getDefinition() method will
|
||||
* always return the definition as determined by the current codebase. This
|
||||
* method, however, returns what the definition was when the last time that
|
||||
* one of the \Drupal\Core\Entity\EntityTypeListenerInterface events was last
|
||||
* fired and completed successfully. In other words, the definition that
|
||||
* the entity type's handlers have incorporated into the application state.
|
||||
* For example, if the entity type's storage handler is SQL-based, the
|
||||
* definition for which database tables were created.
|
||||
*
|
||||
* Application management code can check if getDefinition() differs from
|
||||
* getLastInstalledDefinition() and decide whether to:
|
||||
* - Invoke the appropriate \Drupal\Core\Entity\EntityTypeListenerInterface
|
||||
* event so that handlers react to the new definition.
|
||||
* - Raise a warning that the application state is incompatible with the
|
||||
* codebase.
|
||||
* - Perform some other action.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityTypeInterface|null
|
||||
* The installed entity type definition, or NULL if the entity type has
|
||||
* not yet been installed via onEntityTypeCreate().
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityTypeListenerInterface
|
||||
*/
|
||||
public function getLastInstalledDefinition($entity_type_id);
|
||||
|
||||
/**
|
||||
* Stores the entity type definition in the application state.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type definition.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLastInstalledDefinition(EntityTypeInterface $entity_type);
|
||||
|
||||
/**
|
||||
* Deletes the entity type definition from the application state.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type definition identifier.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function deleteLastInstalledDefinition($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets the entity type's most recently installed field storage definitions.
|
||||
*
|
||||
* During the application lifetime, field storage definitions can change. For
|
||||
* example, updated code can be deployed. The getFieldStorageDefinitions()
|
||||
* method will always return the definitions as determined by the current
|
||||
* codebase. This method, however, returns what the definitions were when the
|
||||
* last time that one of the
|
||||
* \Drupal\Core\Field\FieldStorageDefinitionListenerInterface events was last
|
||||
* fired and completed successfully. In other words, the definitions that
|
||||
* the entity type's handlers have incorporated into the application state.
|
||||
* For example, if the entity type's storage handler is SQL-based, the
|
||||
* definitions for which database tables were created.
|
||||
*
|
||||
* Application management code can check if getFieldStorageDefinitions()
|
||||
* differs from getLastInstalledFieldStorageDefinitions() and decide whether
|
||||
* to:
|
||||
* - Invoke the appropriate
|
||||
* \Drupal\Core\Field\FieldStorageDefinitionListenerInterface
|
||||
* events so that handlers react to the new definitions.
|
||||
* - Raise a warning that the application state is incompatible with the
|
||||
* codebase.
|
||||
* - Perform some other action.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldStorageDefinitionInterface[]
|
||||
* The array of installed field storage definitions for the entity type,
|
||||
* keyed by field name.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityTypeListenerInterface
|
||||
*/
|
||||
public function getLastInstalledFieldStorageDefinitions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Stores the entity type's field storage definitions in the application state.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type identifier.
|
||||
* @param \Drupal\Core\Field\FieldStorageDefinitionInterface[] $storage_definitions
|
||||
* An array of field storage definitions.
|
||||
*/
|
||||
public function setLastInstalledFieldStorageDefinitions($entity_type_id, array $storage_definitions);
|
||||
|
||||
/**
|
||||
* Stores the field storage definition in the application state.
|
||||
*
|
||||
* @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
|
||||
* The field storage definition.
|
||||
*/
|
||||
public function setLastInstalledFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);
|
||||
|
||||
/**
|
||||
* Deletes the field storage definition from the application state.
|
||||
*
|
||||
* @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
|
||||
* The field storage definition.
|
||||
*/
|
||||
public function deleteLastInstalledFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -7,534 +7,28 @@
|
|||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionListenerInterface;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionListenerInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for entity type managers.
|
||||
*
|
||||
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
||||
*/
|
||||
interface EntityManagerInterface extends PluginManagerInterface, EntityTypeListenerInterface, EntityBundleListenerInterface, FieldStorageDefinitionListenerInterface, FieldDefinitionListenerInterface, CachedDiscoveryInterface {
|
||||
interface EntityManagerInterface extends EntityTypeListenerInterface, EntityBundleListenerInterface, FieldStorageDefinitionListenerInterface, FieldDefinitionListenerInterface, EntityTypeManagerInterface, EntityTypeRepositoryInterface, EntityTypeBundleInfoInterface, EntityDisplayRepositoryInterface, EntityFieldManagerInterface, EntityRepositoryInterface {
|
||||
|
||||
/**
|
||||
* Builds a list of entity type labels suitable for a Form API options list.
|
||||
* @see \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledDefinition()
|
||||
*
|
||||
* @param bool $group
|
||||
* (optional) Whether to group entity types by plugin group (e.g. 'content',
|
||||
* 'config'). Defaults to FALSE.
|
||||
*
|
||||
* @return array
|
||||
* An array of entity type labels, keyed by entity type name.
|
||||
*/
|
||||
public function getEntityTypeLabels($group = FALSE);
|
||||
|
||||
/**
|
||||
* Gets the base field definitions for a content entity type.
|
||||
*
|
||||
* Only fields that are not specific to a given bundle or set of bundles are
|
||||
* returned. This excludes configurable fields, as they are always attached
|
||||
* to a specific bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID. Only entity types that implement
|
||||
* \Drupal\Core\Entity\FieldableEntityInterface are supported.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldDefinitionInterface[]
|
||||
* The array of base field definitions for the entity type, keyed by field
|
||||
* name.
|
||||
*
|
||||
* @throws \LogicException
|
||||
* Thrown if one of the entity keys is flagged as translatable.
|
||||
*/
|
||||
public function getBaseFieldDefinitions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets the field definitions for a specific bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID. Only entity types that implement
|
||||
* \Drupal\Core\Entity\FieldableEntityInterface are supported.
|
||||
* @param string $bundle
|
||||
* The bundle.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldDefinitionInterface[]
|
||||
* The array of field definitions for the bundle, keyed by field name.
|
||||
*/
|
||||
public function getFieldDefinitions($entity_type_id, $bundle);
|
||||
|
||||
/**
|
||||
* Gets the field storage definitions for a content entity type.
|
||||
*
|
||||
* This returns all field storage definitions for base fields and bundle
|
||||
* fields of an entity type. Note that field storage definitions of a base
|
||||
* field equal the full base field definition (i.e. they implement
|
||||
* FieldDefinitionInterface), while the storage definitions for bundle fields
|
||||
* may implement FieldStorageDefinitionInterface only.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID. Only content entities are supported.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldStorageDefinitionInterface[]
|
||||
* The array of field storage definitions for the entity type, keyed by
|
||||
* field name.
|
||||
*
|
||||
* @see \Drupal\Core\Field\FieldStorageDefinitionInterface
|
||||
*/
|
||||
public function getFieldStorageDefinitions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets the entity type's most recently installed field storage definitions.
|
||||
*
|
||||
* During the application lifetime, field storage definitions can change. For
|
||||
* example, updated code can be deployed. The getFieldStorageDefinitions()
|
||||
* method will always return the definitions as determined by the current
|
||||
* codebase. This method, however, returns what the definitions were when the
|
||||
* last time that one of the
|
||||
* \Drupal\Core\Field\FieldStorageDefinitionListenerInterface events was last
|
||||
* fired and completed successfully. In other words, the definitions that
|
||||
* the entity type's handlers have incorporated into the application state.
|
||||
* For example, if the entity type's storage handler is SQL-based, the
|
||||
* definitions for which database tables were created.
|
||||
*
|
||||
* Application management code can check if getFieldStorageDefinitions()
|
||||
* differs from getLastInstalledFieldStorageDefinitions() and decide whether
|
||||
* to:
|
||||
* - Invoke the appropriate
|
||||
* \Drupal\Core\Field\FieldStorageDefinitionListenerInterface
|
||||
* events so that handlers react to the new definitions.
|
||||
* - Raise a warning that the application state is incompatible with the
|
||||
* codebase.
|
||||
* - Perform some other action.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldStorageDefinitionInterface[]
|
||||
* The array of installed field storage definitions for the entity type,
|
||||
* keyed by field name.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityTypeListenerInterface
|
||||
*/
|
||||
public function getLastInstalledFieldStorageDefinitions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets a lightweight map of fields across bundles.
|
||||
*
|
||||
* @return array
|
||||
* An array keyed by entity type. Each value is an array which keys are
|
||||
* field names and value is an array with two entries:
|
||||
* - type: The field type.
|
||||
* - bundles: The bundles in which the field appears.
|
||||
*/
|
||||
public function getFieldMap();
|
||||
|
||||
/**
|
||||
* Gets a lightweight map of fields across bundles filtered by field type.
|
||||
*
|
||||
* @param string $field_type
|
||||
* The field type to filter by.
|
||||
*
|
||||
* @return array
|
||||
* An array keyed by entity type. Each value is an array which keys are
|
||||
* field names and value is an array with two entries:
|
||||
* - type: The field type.
|
||||
* - bundles: The bundles in which the field appears.
|
||||
*/
|
||||
public function getFieldMapByFieldType($field_type);
|
||||
|
||||
/**
|
||||
* Creates a new access control handler instance.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type for this access control handler.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityAccessControlHandlerInterface.
|
||||
* A access control handler instance.
|
||||
*/
|
||||
public function getAccessControlHandler($entity_type);
|
||||
|
||||
/**
|
||||
* Creates a new storage instance.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type for this storage.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityStorageInterface
|
||||
* A storage instance.
|
||||
*
|
||||
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
|
||||
*/
|
||||
public function getStorage($entity_type);
|
||||
|
||||
/**
|
||||
* Get the bundle info of all entity types.
|
||||
*
|
||||
* @return array
|
||||
* An array of all bundle information.
|
||||
*/
|
||||
public function getAllBundleInfo();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearCachedDefinitions();
|
||||
|
||||
/**
|
||||
* Clears static and persistent field definition caches.
|
||||
*/
|
||||
public function clearCachedFieldDefinitions();
|
||||
|
||||
/**
|
||||
* Clears static and persistent bundles.
|
||||
*/
|
||||
public function clearCachedBundles();
|
||||
|
||||
/**
|
||||
* Creates a new view builder instance.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type for this view builder.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityViewBuilderInterface.
|
||||
* A view builder instance.
|
||||
*/
|
||||
public function getViewBuilder($entity_type);
|
||||
|
||||
/**
|
||||
* Creates a new entity list builder.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type for this list builder.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityListBuilderInterface
|
||||
* An entity list builder instance.
|
||||
*/
|
||||
public function getListBuilder($entity_type);
|
||||
|
||||
/**
|
||||
* Creates a new form instance.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type for this form.
|
||||
* @param string $operation
|
||||
* The name of the operation to use, e.g., 'default'.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityFormInterface
|
||||
* A form instance.
|
||||
*/
|
||||
public function getFormObject($entity_type, $operation);
|
||||
|
||||
/**
|
||||
* Gets all route provider instances.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type for this route providers.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\Routing\EntityRouteProviderInterface[]
|
||||
*/
|
||||
public function getRouteProviders($entity_type);
|
||||
|
||||
/**
|
||||
* Checks whether a certain entity type has a certain handler.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The name of the entity type.
|
||||
* @param string $handler_type
|
||||
* The name of the handler.
|
||||
*
|
||||
* @return bool
|
||||
* Returns TRUE if the entity type has the handler, else FALSE.
|
||||
*/
|
||||
public function hasHandler($entity_type, $handler_type);
|
||||
|
||||
/**
|
||||
* Creates a new handler instance for a entity type and handler type.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type for this handler.
|
||||
* @param string $handler_type
|
||||
* The handler type to create an instance for.
|
||||
*
|
||||
* @return object
|
||||
* A handler instance.
|
||||
*
|
||||
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
|
||||
*/
|
||||
public function getHandler($entity_type, $handler_type);
|
||||
|
||||
/**
|
||||
* Creates new handler instance.
|
||||
*
|
||||
* Usually \Drupal\Core\Entity\EntityManagerInterface::getHandler() is
|
||||
* preferred since that method has additional checking that the class exists
|
||||
* and has static caches.
|
||||
*
|
||||
* @param mixed $class
|
||||
* The handler class to instantiate.
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $definition
|
||||
* The entity type definition.
|
||||
*
|
||||
* @return object
|
||||
* A handler instance.
|
||||
*/
|
||||
public function createHandlerInstance($class, EntityTypeInterface $definition = null);
|
||||
|
||||
/**
|
||||
* Gets the bundle info of an entity type.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return array
|
||||
* Returns the bundle information for the specified entity type.
|
||||
*/
|
||||
public function getBundleInfo($entity_type);
|
||||
|
||||
/**
|
||||
* Gets the "extra fields" for a bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID.
|
||||
* @param string $bundle
|
||||
* The bundle name.
|
||||
*
|
||||
* @return array
|
||||
* A nested array of 'pseudo-field' elements. Each list is nested within the
|
||||
* following keys: entity type, bundle name, context (either 'form' or
|
||||
* 'display'). The keys are the name of the elements as appearing in the
|
||||
* renderable array (either the entity form or the displayed entity). The
|
||||
* value is an associative array:
|
||||
* - label: The human readable name of the element. Make sure you sanitize
|
||||
* this appropriately.
|
||||
* - description: A short description of the element contents.
|
||||
* - weight: The default weight of the element.
|
||||
* - visible: (optional) The default visibility of the element. Defaults to
|
||||
* TRUE.
|
||||
* - edit: (optional) String containing markup (normally a link) used as the
|
||||
* element's 'edit' operation in the administration interface. Only for
|
||||
* 'form' context.
|
||||
* - delete: (optional) String containing markup (normally a link) used as the
|
||||
* element's 'delete' operation in the administration interface. Only for
|
||||
* 'form' context.
|
||||
*/
|
||||
public function getExtraFields($entity_type_id, $bundle);
|
||||
|
||||
/**
|
||||
* Gets the entity translation to be used in the given context.
|
||||
*
|
||||
* This will check whether a translation for the desired language is available
|
||||
* and if not, it will fall back to the most appropriate translation based on
|
||||
* the provided context.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity whose translation will be returned.
|
||||
* @param string $langcode
|
||||
* (optional) The language of the current context. Defaults to the current
|
||||
* content language.
|
||||
* @param array $context
|
||||
* (optional) An associative array of arbitrary data that can be useful to
|
||||
* determine the proper fallback sequence.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface
|
||||
* An entity object for the translated data.
|
||||
*
|
||||
* @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()
|
||||
*/
|
||||
public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = array());
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityTypeInterface|null
|
||||
*/
|
||||
public function getDefinition($entity_type_id, $exception_on_invalid = TRUE);
|
||||
|
||||
/**
|
||||
* Gets the entity type definition in its most recently installed state.
|
||||
*
|
||||
* During the application lifetime, entity type definitions can change. For
|
||||
* example, updated code can be deployed. The getDefinition() method will
|
||||
* always return the definition as determined by the current codebase. This
|
||||
* method, however, returns what the definition was when the last time that
|
||||
* one of the \Drupal\Core\Entity\EntityTypeListenerInterface events was last
|
||||
* fired and completed successfully. In other words, the definition that
|
||||
* the entity type's handlers have incorporated into the application state.
|
||||
* For example, if the entity type's storage handler is SQL-based, the
|
||||
* definition for which database tables were created.
|
||||
*
|
||||
* Application management code can check if getDefinition() differs from
|
||||
* getLastInstalledDefinition() and decide whether to:
|
||||
* - Invoke the appropriate \Drupal\Core\Entity\EntityTypeListenerInterface
|
||||
* event so that handlers react to the new definition.
|
||||
* - Raise a warning that the application state is incompatible with the
|
||||
* codebase.
|
||||
* - Perform some other action.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityTypeInterface|null
|
||||
* The installed entity type definition, or NULL if the entity type has
|
||||
* not yet been installed via onEntityTypeCreate().
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityTypeListenerInterface
|
||||
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
||||
*/
|
||||
public function getLastInstalledDefinition($entity_type_id);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @see \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledFieldStorageDefinitions()
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityTypeInterface[]
|
||||
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
||||
*/
|
||||
public function getDefinitions();
|
||||
|
||||
/**
|
||||
* Gets the entity view mode info for all entity types.
|
||||
*
|
||||
* @return array
|
||||
* The view mode info for all entity types.
|
||||
*/
|
||||
public function getAllViewModes();
|
||||
|
||||
/**
|
||||
* Gets the entity view mode info for a specific entity type.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose view mode info should be returned.
|
||||
*
|
||||
* @return array
|
||||
* The view mode info for a specific entity type.
|
||||
*/
|
||||
public function getViewModes($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets the entity form mode info for all entity types.
|
||||
*
|
||||
* @return array
|
||||
* The form mode info for all entity types.
|
||||
*/
|
||||
public function getAllFormModes();
|
||||
|
||||
/**
|
||||
* Gets the entity form mode info for a specific entity type.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose form mode info should be returned.
|
||||
*
|
||||
* @return array
|
||||
* The form mode info for a specific entity type.
|
||||
*/
|
||||
public function getFormModes($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets an array of view mode options.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose view mode options should be returned.
|
||||
*
|
||||
* @return array
|
||||
* An array of view mode labels, keyed by the display mode ID.
|
||||
*/
|
||||
public function getViewModeOptions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Gets an array of form mode options.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose form mode options should be returned.
|
||||
*
|
||||
* @return array
|
||||
* An array of form mode labels, keyed by the display mode ID.
|
||||
*/
|
||||
public function getFormModeOptions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Returns an array of enabled view mode options by bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose view mode options should be returned.
|
||||
* @param string $bundle
|
||||
* The name of the bundle.
|
||||
*
|
||||
* @return array
|
||||
* An array of view mode labels, keyed by the display mode ID.
|
||||
*/
|
||||
public function getViewModeOptionsByBundle($entity_type_id, $bundle);
|
||||
|
||||
/**
|
||||
* Returns an array of enabled form mode options by bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose form mode options should be returned.
|
||||
* @param string $bundle
|
||||
* The name of the bundle.
|
||||
*
|
||||
* @return array
|
||||
* An array of form mode labels, keyed by the display mode ID.
|
||||
*/
|
||||
public function getFormModeOptionsByBundle($entity_type_id, $bundle);
|
||||
|
||||
/**
|
||||
* Loads an entity by UUID.
|
||||
*
|
||||
* Note that some entity types may not support UUIDs.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID to load from.
|
||||
* @param string $uuid
|
||||
* The UUID of the entity to load.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface|null
|
||||
* The entity object, or NULL if there is no entity with the given UUID.
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\EntityStorageException
|
||||
* Thrown in case the requested entity type does not support UUIDs.
|
||||
*/
|
||||
public function loadEntityByUuid($entity_type_id, $uuid);
|
||||
|
||||
/**
|
||||
* Loads an entity by the config target identifier.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID to load from.
|
||||
* @param string $target
|
||||
* The configuration target to load, as returned from
|
||||
* \Drupal\Core\Entity\EntityInterface::getConfigTarget().
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface|null
|
||||
* The entity object, or NULL if there is no entity with the given config
|
||||
* target identifier.
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\EntityStorageException
|
||||
* Thrown if the target identifier is a UUID but the entity type does not
|
||||
* support UUIDs.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityInterface::getConfigTarget()
|
||||
*/
|
||||
public function loadEntityByConfigTarget($entity_type_id, $target);
|
||||
|
||||
/**
|
||||
* Gets the entity type ID based on the class that is called on.
|
||||
*
|
||||
* Compares the class this is called on against the known entity classes
|
||||
* and returns the entity type ID of a direct match or a subclass as fallback,
|
||||
* to support entity type definitions that were altered.
|
||||
*
|
||||
* @param string $class_name
|
||||
* Class name to use for searching the entity type ID.
|
||||
*
|
||||
* @return string
|
||||
* The entity type ID.
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\Exception\AmbiguousEntityClassException
|
||||
* Thrown when multiple subclasses correspond to the called class.
|
||||
* @throws \Drupal\Core\Entity\Exception\NoCorrespondingEntityClassException
|
||||
* Thrown when no entity class corresponds to the called class.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Entity::load()
|
||||
* @see \Drupal\Core\Entity\Entity::loadMultiple()
|
||||
*/
|
||||
public function getEntityTypeFromClass($class_name);
|
||||
public function getLastInstalledFieldStorageDefinitions($entity_type_id);
|
||||
|
||||
}
|
||||
|
|
120
core/lib/Drupal/Core/Entity/EntityRepository.php
Normal file
120
core/lib/Drupal/Core/Entity/EntityRepository.php
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityRepository.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\TypedData\TranslatableInterface;
|
||||
|
||||
/**
|
||||
* Provides several mechanisms for retrieving entities.
|
||||
*/
|
||||
class EntityRepository implements EntityRepositoryInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityRepository.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->languageManager = $language_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadEntityByUuid($entity_type_id, $uuid) {
|
||||
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
|
||||
|
||||
if (!$uuid_key = $entity_type->getKey('uuid')) {
|
||||
throw new EntityStorageException("Entity type $entity_type_id does not support UUIDs.");
|
||||
}
|
||||
|
||||
$entities = $this->entityTypeManager->getStorage($entity_type_id)->loadByProperties([$uuid_key => $uuid]);
|
||||
|
||||
return reset($entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadEntityByConfigTarget($entity_type_id, $target) {
|
||||
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
|
||||
|
||||
// For configuration entities, the config target is given by the entity ID.
|
||||
// @todo Consider adding a method to allow entity types to indicate the
|
||||
// target identifier key rather than hard-coding this check. Issue:
|
||||
// https://www.drupal.org/node/2412983.
|
||||
if ($entity_type instanceof ConfigEntityTypeInterface) {
|
||||
$entity = $this->entityTypeManager->getStorage($entity_type_id)->load($target);
|
||||
}
|
||||
|
||||
// For content entities, the config target is given by the UUID.
|
||||
else {
|
||||
$entity = $this->loadEntityByUuid($entity_type_id, $target);
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = array()) {
|
||||
$translation = $entity;
|
||||
|
||||
if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) {
|
||||
if (empty($langcode)) {
|
||||
$langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
|
||||
$entity->addCacheContexts(['languages:' . LanguageInterface::TYPE_CONTENT]);
|
||||
}
|
||||
|
||||
// Retrieve language fallback candidates to perform the entity language
|
||||
// negotiation, unless the current translation is already the desired one.
|
||||
if ($entity->language()->getId() != $langcode) {
|
||||
$context['data'] = $entity;
|
||||
$context += array('operation' => 'entity_view', 'langcode' => $langcode);
|
||||
$candidates = $this->languageManager->getFallbackCandidates($context);
|
||||
|
||||
// Ensure the default language has the proper language code.
|
||||
$default_language = $entity->getUntranslated()->language();
|
||||
$candidates[$default_language->getId()] = LanguageInterface::LANGCODE_DEFAULT;
|
||||
|
||||
// Return the most fitting entity translation.
|
||||
foreach ($candidates as $candidate) {
|
||||
if ($entity->hasTranslation($candidate)) {
|
||||
$translation = $entity->getTranslation($candidate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $translation;
|
||||
}
|
||||
|
||||
}
|
77
core/lib/Drupal/Core/Entity/EntityRepositoryInterface.php
Normal file
77
core/lib/Drupal/Core/Entity/EntityRepositoryInterface.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityRepositoryInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
/**
|
||||
* Provides an interface for an entity repository.
|
||||
*/
|
||||
interface EntityRepositoryInterface {
|
||||
|
||||
/**
|
||||
* Loads an entity by UUID.
|
||||
*
|
||||
* Note that some entity types may not support UUIDs.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID to load from.
|
||||
* @param string $uuid
|
||||
* The UUID of the entity to load.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface|null
|
||||
* The entity object, or NULL if there is no entity with the given UUID.
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\EntityStorageException
|
||||
* Thrown in case the requested entity type does not support UUIDs.
|
||||
*/
|
||||
public function loadEntityByUuid($entity_type_id, $uuid);
|
||||
|
||||
/**
|
||||
* Loads an entity by the config target identifier.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type ID to load from.
|
||||
* @param string $target
|
||||
* The configuration target to load, as returned from
|
||||
* \Drupal\Core\Entity\EntityInterface::getConfigTarget().
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface|null
|
||||
* The entity object, or NULL if there is no entity with the given config
|
||||
* target identifier.
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\EntityStorageException
|
||||
* Thrown if the target identifier is a UUID but the entity type does not
|
||||
* support UUIDs.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityInterface::getConfigTarget()
|
||||
*/
|
||||
public function loadEntityByConfigTarget($entity_type_id, $target);
|
||||
|
||||
/**
|
||||
* Gets the entity translation to be used in the given context.
|
||||
*
|
||||
* This will check whether a translation for the desired language is available
|
||||
* and if not, it will fall back to the most appropriate translation based on
|
||||
* the provided context.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity whose translation will be returned.
|
||||
* @param string $langcode
|
||||
* (optional) The language of the current context. Defaults to the current
|
||||
* content language.
|
||||
* @param array $context
|
||||
* (optional) An associative array of arbitrary data that can be useful to
|
||||
* determine the proper fallback sequence.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface
|
||||
* An entity object for the translated data.
|
||||
*
|
||||
* @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()
|
||||
*/
|
||||
public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = array());
|
||||
|
||||
}
|
133
core/lib/Drupal/Core/Entity/EntityTypeBundleInfo.php
Normal file
133
core/lib/Drupal/Core/Entity/EntityTypeBundleInfo.php
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityTypeBundleInfo.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Cache\UseCacheBackendTrait;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\TypedData\TypedDataManagerInterface;
|
||||
|
||||
/**
|
||||
* Provides discovery and retrieval of entity type bundles.
|
||||
*/
|
||||
class EntityTypeBundleInfo implements EntityTypeBundleInfoInterface {
|
||||
|
||||
use UseCacheBackendTrait;
|
||||
|
||||
/**
|
||||
* Static cache of bundle information.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $bundleInfo;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* The typed data manager.
|
||||
*
|
||||
* @var \Drupal\Core\TypedData\TypedDataManagerInterface
|
||||
*/
|
||||
protected $typedDataManager;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityTypeBundleInfo.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
|
||||
* The typed data manager.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* The cache backend.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, TypedDataManagerInterface $typed_data_manager, CacheBackendInterface $cache_backend) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->languageManager = $language_manager;
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->typedDataManager = $typed_data_manager;
|
||||
$this->cacheBackend = $cache_backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBundleInfo($entity_type) {
|
||||
$bundle_info = $this->getAllBundleInfo();
|
||||
return isset($bundle_info[$entity_type]) ? $bundle_info[$entity_type] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllBundleInfo() {
|
||||
if (empty($this->bundleInfo)) {
|
||||
$langcode = $this->languageManager->getCurrentLanguage()->getId();
|
||||
if ($cache = $this->cacheGet("entity_bundle_info:$langcode")) {
|
||||
$this->bundleInfo = $cache->data;
|
||||
}
|
||||
else {
|
||||
$this->bundleInfo = $this->moduleHandler->invokeAll('entity_bundle_info');
|
||||
// First look for entity types that act as bundles for others, load them
|
||||
// and add them as bundles.
|
||||
foreach ($this->entityTypeManager->getDefinitions() as $type => $entity_type) {
|
||||
if ($entity_type->getBundleOf()) {
|
||||
foreach ($this->entityTypeManager->getStorage($type)->loadMultiple() as $entity) {
|
||||
$this->bundleInfo[$entity_type->getBundleOf()][$entity->id()]['label'] = $entity->label();
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($this->entityTypeManager->getDefinitions() as $type => $entity_type) {
|
||||
// If no bundles are provided, use the entity type name and label.
|
||||
if (!isset($this->bundleInfo[$type])) {
|
||||
$this->bundleInfo[$type][$type]['label'] = $entity_type->getLabel();
|
||||
}
|
||||
}
|
||||
$this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo);
|
||||
$this->cacheSet("entity_bundle_info:$langcode", $this->bundleInfo, Cache::PERMANENT, ['entity_types', 'entity_bundles']);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->bundleInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearCachedBundles() {
|
||||
$this->bundleInfo = [];
|
||||
Cache::invalidateTags(['entity_bundles']);
|
||||
// Entity bundles are exposed as data types, clear that cache too.
|
||||
$this->typedDataManager->clearCachedDefinitions();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityTypeBundleInfoInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
/**
|
||||
* Provides an interface for an entity type bundle info.
|
||||
*/
|
||||
interface EntityTypeBundleInfoInterface {
|
||||
|
||||
/**
|
||||
* Get the bundle info of all entity types.
|
||||
*
|
||||
* @return array
|
||||
* An array of all bundle information.
|
||||
*/
|
||||
public function getAllBundleInfo();
|
||||
|
||||
/**
|
||||
* Gets the bundle info of an entity type.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return array
|
||||
* Returns the bundle information for the specified entity type.
|
||||
*/
|
||||
public function getBundleInfo($entity_type);
|
||||
|
||||
/**
|
||||
* Clears static and persistent bundles.
|
||||
*/
|
||||
public function clearCachedBundles();
|
||||
|
||||
}
|
123
core/lib/Drupal/Core/Entity/EntityTypeListener.php
Normal file
123
core/lib/Drupal/Core/Entity/EntityTypeListener.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityTypeListener.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* Reacts to entity type CRUD on behalf of the Entity system.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityTypeEvents
|
||||
*/
|
||||
class EntityTypeListener implements EntityTypeListenerInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The event dispatcher.
|
||||
*
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* The entity last installed schema repository.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
|
||||
*/
|
||||
protected $entityLastInstalledSchemaRepository;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityTypeListener.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
|
||||
* The entity field manager.
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
|
||||
* The event dispatcher.
|
||||
* @param \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository
|
||||
* The entity last installed schema repository.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, EventDispatcherInterface $event_dispatcher, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
$this->eventDispatcher = $event_dispatcher;
|
||||
$this->entityLastInstalledSchemaRepository = $entity_last_installed_schema_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
|
||||
$entity_type_id = $entity_type->id();
|
||||
|
||||
// @todo Forward this to all interested handlers, not only storage, once
|
||||
// iterating handlers is possible: https://www.drupal.org/node/2332857.
|
||||
$storage = $this->entityTypeManager->getStorage($entity_type_id);
|
||||
if ($storage instanceof EntityTypeListenerInterface) {
|
||||
$storage->onEntityTypeCreate($entity_type);
|
||||
}
|
||||
|
||||
$this->eventDispatcher->dispatch(EntityTypeEvents::CREATE, new EntityTypeEvent($entity_type));
|
||||
|
||||
$this->entityLastInstalledSchemaRepository->setLastInstalledDefinition($entity_type);
|
||||
if ($entity_type->isSubclassOf(FieldableEntityInterface::class)) {
|
||||
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
|
||||
$entity_type_id = $entity_type->id();
|
||||
|
||||
// @todo Forward this to all interested handlers, not only storage, once
|
||||
// iterating handlers is possible: https://www.drupal.org/node/2332857.
|
||||
$storage = $this->entityTypeManager->getStorage($entity_type_id);
|
||||
if ($storage instanceof EntityTypeListenerInterface) {
|
||||
$storage->onEntityTypeUpdate($entity_type, $original);
|
||||
}
|
||||
|
||||
$this->eventDispatcher->dispatch(EntityTypeEvents::UPDATE, new EntityTypeEvent($entity_type, $original));
|
||||
|
||||
$this->entityLastInstalledSchemaRepository->setLastInstalledDefinition($entity_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
|
||||
$entity_type_id = $entity_type->id();
|
||||
|
||||
// @todo Forward this to all interested handlers, not only storage, once
|
||||
// iterating handlers is possible: https://www.drupal.org/node/2332857.
|
||||
$storage = $this->entityTypeManager->getStorage($entity_type_id);
|
||||
if ($storage instanceof EntityTypeListenerInterface) {
|
||||
$storage->onEntityTypeDelete($entity_type);
|
||||
}
|
||||
|
||||
$this->eventDispatcher->dispatch(EntityTypeEvents::DELETE, new EntityTypeEvent($entity_type));
|
||||
|
||||
$this->entityLastInstalledSchemaRepository->deleteLastInstalledDefinition($entity_type_id);
|
||||
}
|
||||
|
||||
}
|
266
core/lib/Drupal/Core/Entity/EntityTypeManager.php
Normal file
266
core/lib/Drupal/Core/Entity/EntityTypeManager.php
Normal file
|
@ -0,0 +1,266 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\EntityTypeManager.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\DependencyInjection\ClassResolverInterface;
|
||||
use Drupal\Core\Entity\Exception\InvalidLinkTemplateException;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* Manages entity type plugin definitions.
|
||||
*
|
||||
* Each entity type definition array is set in the entity type's
|
||||
* annotation and altered by hook_entity_type_alter().
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Annotation\EntityType
|
||||
* @see \Drupal\Core\Entity\EntityInterface
|
||||
* @see \Drupal\Core\Entity\EntityTypeInterface
|
||||
* @see hook_entity_type_alter()
|
||||
*/
|
||||
class EntityTypeManager extends DefaultPluginManager implements EntityTypeManagerInterface, ContainerAwareInterface {
|
||||
|
||||
use ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* Contains instantiated handlers keyed by handler type and entity type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $handlers = [];
|
||||
|
||||
/**
|
||||
* The string translation service.
|
||||
*
|
||||
* @var \Drupal\Core\StringTranslation\TranslationInterface
|
||||
*/
|
||||
protected $stringTranslation;
|
||||
|
||||
/**
|
||||
* The class resolver.
|
||||
*
|
||||
* @var \Drupal\Core\DependencyInjection\ClassResolverInterface
|
||||
*/
|
||||
protected $classResolver;
|
||||
|
||||
/**
|
||||
* Constructs a new Entity plugin manager.
|
||||
*
|
||||
* @param \Traversable $namespaces
|
||||
* An object that implements \Traversable which contains the root paths
|
||||
* keyed by the corresponding namespace to look for plugin implementations,
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
|
||||
* The cache backend to use.
|
||||
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
|
||||
* The string translation.
|
||||
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
|
||||
* The class resolver.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, TranslationInterface $string_translation, ClassResolverInterface $class_resolver) {
|
||||
parent::__construct('Entity', $namespaces, $module_handler, 'Drupal\Core\Entity\EntityInterface');
|
||||
|
||||
$this->setCacheBackend($cache, 'entity_type', ['entity_types']);
|
||||
$this->alterInfo('entity_type');
|
||||
|
||||
$this->discovery = new AnnotatedClassDiscovery('Entity', $namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
|
||||
$this->stringTranslation = $string_translation;
|
||||
$this->classResolver = $class_resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processDefinition(&$definition, $plugin_id) {
|
||||
/** @var \Drupal\Core\Entity\EntityTypeInterface $definition */
|
||||
parent::processDefinition($definition, $plugin_id);
|
||||
|
||||
// All link templates must have a leading slash.
|
||||
foreach ((array) $definition->getLinkTemplates() as $link_relation_name => $link_template) {
|
||||
if ($link_template[0] != '/') {
|
||||
throw new InvalidLinkTemplateException("Link template '$link_relation_name' for entity type '$plugin_id' must start with a leading slash, the current link template is '$link_template'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function findDefinitions() {
|
||||
$definitions = $this->getDiscovery()->getDefinitions();
|
||||
|
||||
// Directly call the hook implementations to pass the definitions to them
|
||||
// by reference, so new entity types can be added.
|
||||
foreach ($this->moduleHandler->getImplementations('entity_type_build') as $module) {
|
||||
$function = $module . '_' . 'entity_type_build';
|
||||
$function($definitions);
|
||||
}
|
||||
foreach ($definitions as $plugin_id => $definition) {
|
||||
$this->processDefinition($definition, $plugin_id);
|
||||
}
|
||||
$this->alterDefinitions($definitions);
|
||||
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefinition($entity_type_id, $exception_on_invalid = TRUE) {
|
||||
if (($entity_type = parent::getDefinition($entity_type_id, FALSE)) && class_exists($entity_type->getClass())) {
|
||||
return $entity_type;
|
||||
}
|
||||
elseif (!$exception_on_invalid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
throw new PluginNotFoundException($entity_type_id, sprintf('The "%s" entity type does not exist.', $entity_type_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearCachedDefinitions() {
|
||||
parent::clearCachedDefinitions();
|
||||
$this->handlers = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function useCaches($use_caches = FALSE) {
|
||||
parent::useCaches($use_caches);
|
||||
if (!$use_caches) {
|
||||
$this->handlers = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasHandler($entity_type, $handler_type) {
|
||||
if ($definition = $this->getDefinition($entity_type, FALSE)) {
|
||||
return $definition->hasHandlerClass($handler_type);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStorage($entity_type) {
|
||||
return $this->getHandler($entity_type, 'storage');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getListBuilder($entity_type) {
|
||||
return $this->getHandler($entity_type, 'list_builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormObject($entity_type, $operation) {
|
||||
if (!isset($this->handlers['form'][$operation][$entity_type])) {
|
||||
if (!$class = $this->getDefinition($entity_type, TRUE)->getFormClass($operation)) {
|
||||
throw new InvalidPluginDefinitionException($entity_type, sprintf('The "%s" entity type did not specify a "%s" form class.', $entity_type, $operation));
|
||||
}
|
||||
|
||||
$form_object = $this->classResolver->getInstanceFromDefinition($class);
|
||||
|
||||
$form_object
|
||||
->setStringTranslation($this->stringTranslation)
|
||||
->setModuleHandler($this->moduleHandler)
|
||||
->setEntityTypeManager($this)
|
||||
->setOperation($operation)
|
||||
// The entity manager cannot be injected due to a circular dependency.
|
||||
// @todo Remove this set call in https://www.drupal.org/node/2603542.
|
||||
->setEntityManager(\Drupal::entityManager());
|
||||
$this->handlers['form'][$operation][$entity_type] = $form_object;
|
||||
}
|
||||
|
||||
return $this->handlers['form'][$operation][$entity_type];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRouteProviders($entity_type) {
|
||||
if (!isset($this->handlers['route_provider'][$entity_type])) {
|
||||
$route_provider_classes = $this->getDefinition($entity_type, TRUE)->getRouteProviderClasses();
|
||||
|
||||
foreach ($route_provider_classes as $type => $class) {
|
||||
$this->handlers['route_provider'][$entity_type][$type] = $this->createHandlerInstance($class, $this->getDefinition($entity_type));
|
||||
}
|
||||
}
|
||||
|
||||
return isset($this->handlers['route_provider'][$entity_type]) ? $this->handlers['route_provider'][$entity_type] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewBuilder($entity_type) {
|
||||
return $this->getHandler($entity_type, 'view_builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAccessControlHandler($entity_type) {
|
||||
return $this->getHandler($entity_type, 'access');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHandler($entity_type, $handler_type) {
|
||||
if (!isset($this->handlers[$handler_type][$entity_type])) {
|
||||
$definition = $this->getDefinition($entity_type);
|
||||
$class = $definition->getHandlerClass($handler_type);
|
||||
if (!$class) {
|
||||
throw new InvalidPluginDefinitionException($entity_type, sprintf('The "%s" entity type did not specify a %s handler.', $entity_type, $handler_type));
|
||||
}
|
||||
$this->handlers[$handler_type][$entity_type] = $this->createHandlerInstance($class, $definition);
|
||||
}
|
||||
|
||||
return $this->handlers[$handler_type][$entity_type];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createHandlerInstance($class, EntityTypeInterface $definition = NULL) {
|
||||
if (is_subclass_of($class, 'Drupal\Core\Entity\EntityHandlerInterface')) {
|
||||
$handler = $class::createInstance($this->container, $definition);
|
||||
}
|
||||
else {
|
||||
$handler = new $class($definition);
|
||||
}
|
||||
if (method_exists($handler, 'setModuleHandler')) {
|
||||
$handler->setModuleHandler($this->moduleHandler);
|
||||
}
|
||||
if (method_exists($handler, 'setStringTranslation')) {
|
||||
$handler->setStringTranslation($this->stringTranslation);
|
||||
}
|
||||
|
||||
return $handler;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue