diff --git c/core/core.services.yml w/core/core.services.yml index e4d2ece..65882af 100644 --- c/core/core.services.yml +++ w/core/core.services.yml @@ -176,7 +176,7 @@ services: arguments: ['@container.namespaces', '@controller_resolver', '@request', '@module_handler', '@cache.cache', '@language_manager'] plugin.manager.menu.local_task: class: Drupal\Core\Menu\LocalTaskManager - arguments: ['@controller_resolver', '@request', '@router.route_provider', '@module_handler', '@cache.cache', '@language_manager'] + arguments: ['@container.namespaces', '@controller_resolver', '@request', '@router.route_provider', '@module_handler', '@cache.cache', '@language_manager'] request: class: Symfony\Component\HttpFoundation\Request # @TODO the synthetic setting must be uncommented whenever drupal_session_initialize() diff --git c/core/includes/entity.inc w/core/includes/entity.inc index 2590ce9..d49f5cd 100644 --- c/core/includes/entity.inc +++ w/core/includes/entity.inc @@ -41,6 +41,7 @@ function entity_get_info($entity_type = NULL) { */ function entity_info_cache_clear() { drupal_static_reset('entity_get_view_modes'); + drupal_static_reset('entity_get_bundles'); // Clear all languages. Drupal::entityManager()->clearCachedDefinitions(); Drupal::entityManager()->clearCachedFieldDefinitions(); @@ -55,17 +56,35 @@ function entity_info_cache_clear() { * * @return array * The bundle info for a specific entity type, or all entity types. - * - * @see \Drupal\Core\Entity\EntityManager::getBundleInfo() - * @see \Drupal\Core\Entity\EntityManager::getAllBundleInfo() */ function entity_get_bundles($entity_type = NULL) { - if (isset($entity_type)) { - return Drupal::entityManager()->getBundleInfo($entity_type); + $bundles = &drupal_static(__FUNCTION__); + if (!$bundles) { + $langcode = language(Language::TYPE_INTERFACE)->id; + if ($cache = cache()->get("entity_bundle_info:$langcode")) { + $bundles = $cache->data; + } + else { + $bundles = Drupal::moduleHandler()->invokeAll('entity_bundle_info'); + // If no bundles are provided, use the entity type name and label. + foreach (entity_get_info() as $type => $entity_info) { + if (!isset($bundles[$type])) { + $bundles[$type][$type]['label'] = $entity_info['label']; + } + } + drupal_alter('entity_bundle_info', $bundles); + cache()->set("entity_bundle_info:$langcode", $bundles, CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE)); + } } - else { - return Drupal::entityManager()->getAllBundleInfo(); + + if (empty($entity_type)) { + return $bundles; } + elseif (isset($bundles[$entity_type])) { + return $bundles[$entity_type]; + } + + return array(); } /** diff --git c/core/includes/menu.inc w/core/includes/menu.inc index 3705382..0b59cfe 100644 --- c/core/includes/menu.inc +++ w/core/includes/menu.inc @@ -1278,14 +1278,8 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail = // Load the router item corresponding to the current page. $request = \Drupal::request(); $system_path = NULL; - if ($route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME)) { - // @todo https://drupal.org/node/2068471 is adding support so we can tell - // if this is called on a 404/403 page. - $system_path = $request->attributes->get('_system_path'); - $page_not_403 = 1; - } // @todo Remove once the old router system is removed. - elseif ($request->attributes->has('_legacy')) { + if ($request->attributes->has('_legacy')) { // Page is a 404 if no item is loaded. if ($item = menu_get_item($active_path)) { $system_path = $item['href']; @@ -1294,6 +1288,12 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail = $page_not_403 = (int) $item['access']; } } + elseif ($route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME)) { + // @todo https://drupal.org/node/2068471 is adding support so we can tell + // if this is called on a 404/403 page. + $system_path = $request->attributes->get('_system_path'); + $page_not_403 = 1; + } if (isset($system_path)) { if (isset($max_depth)) { $max_depth = min($max_depth, MENU_MAX_DEPTH); diff --git c/core/lib/Drupal/Core/Annotation/Menu/LocalTask.php w/core/lib/Drupal/Core/Annotation/Menu/LocalTask.php new file mode 100644 index 0000000..52ef6a1 --- /dev/null +++ w/core/lib/Drupal/Core/Annotation/Menu/LocalTask.php @@ -0,0 +1,70 @@ +bundleInfo = NULL; - } - - - /** * Checks whether a certain entity type has a certain controller. * * @param string $entity_type @@ -528,46 +511,4 @@ public function clearCachedFieldDefinitions() { $this->cache->deleteTags(array('entity_field_info' => TRUE)); } - /** - * Get 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) { - $bundle_info = $this->getAllBundleInfo(); - return isset($bundle_info[$entity_type]) ? $bundle_info[$entity_type] : array(); - } - - /** - * Get the bundle info of all entity types. - * - * @return array - * An array of all bundle information. - */ - public function getAllBundleInfo() { - if (!isset($this->bundleInfo)) { - $langcode = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id; - if ($cache = $this->cache->get("entity_bundle_info:$langcode")) { - $this->bundleInfo = $cache->data; - } - else { - $this->bundleInfo = $this->moduleHandler->invokeAll('entity_bundle_info'); - // If no bundles are provided, use the entity type name and label. - foreach ($this->getDefinitions() as $type => $entity_info) { - if (!isset($this->bundleInfo[$type])) { - $this->bundleInfo[$type][$type]['label'] = $entity_info['label']; - } - } - $this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo); - $this->cache->set("entity_bundle_info:$langcode", $this->bundleInfo, CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE)); - } - } - - return $this->bundleInfo; - } - } diff --git c/core/lib/Drupal/Core/Menu/LocalTaskBase.php w/core/lib/Drupal/Core/Menu/LocalTaskBase.php new file mode 100644 index 0000000..7568d2b --- /dev/null +++ w/core/lib/Drupal/Core/Menu/LocalTaskBase.php @@ -0,0 +1,155 @@ +t = $string_translation; + $this->generator = $generator; + parent::__construct($configuration, $plugin_id, $plugin_definition); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('string_translation'), + $container->get('url_generator') + ); + } + + /** + * {@inheritdoc} + */ + public function getRouteName() { + return $this->pluginDefinition['route_name']; + } + + /** + * {@inheritdoc} + */ + public function getTitle() { + // Subclasses may pull in the request or specific attributes as parameters. + return $this->pluginDefinition['title']; + } + + /** + * {@inheritdoc} + */ + public function getPath() { + // Subclasses may set a request into the generator or use any desired method + // to generate the path. + // @todo - use the new method from https://drupal.org/node/2031353 + $path = $this->generator->generate($this->getRouteName()); + // In order to get the Drupal path the base URL has to be stripped off. + $base_url = $this->generator->getContext()->getBaseUrl(); + if (!empty($base_url) && strpos($path, $base_url) === 0) { + $path = substr($path, strlen($base_url)); + } + return trim($path, '/'); + } + + /** + * Returns the weight of the local task. + * + * @return int + * The weight of the task. If not defined in the annotation returns 0 by + * default or -10 for the root tab. + */ + public function getWeight() { + // By default the weight is 0, or -10 for the root tab. + if (!isset($this->pluginDefinition['weight'])) { + if ($this->pluginDefinition['tab_root_id'] == $this->pluginDefinition['id']) { + $this->pluginDefinition['weight'] = -10; + } + else { + $this->pluginDefinition['weight'] = 0; + } + } + return (int) $this->pluginDefinition['weight']; + } + + /** + * {@inheritdoc} + */ + public function getOptions() { + $options = $this->pluginDefinition['options']; + if ($this->active) { + if (empty($options['attributes']['class']) || !in_array('active', $options['attributes']['class'])) { + $options['attributes']['class'][] = 'active'; + } + } + return (array) $options; + } + + /** + * {@inheritdoc} + */ + public function setActive($active = TRUE) { + $this->active = $active; + return $this; + } + + /** + * {@inheritdoc} + */ + public function getActive() { + return $this->active; + } + +} diff --git c/core/lib/Drupal/Core/Menu/LocalTaskDefault.php w/core/lib/Drupal/Core/Menu/LocalTaskDefault.php deleted file mode 100644 index 5021e90..0000000 --- c/core/lib/Drupal/Core/Menu/LocalTaskDefault.php +++ /dev/null @@ -1,164 +0,0 @@ -stringTranslation = $string_translation; - $this->generator = $generator; - parent::__construct($configuration, $plugin_id, $plugin_definition); - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('string_translation'), - $container->get('url_generator') - ); - } - - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->stringTranslation->translate($string, $args, $options); - } - - /** - * {@inheritdoc} - */ - public function getRouteName() { - return $this->pluginDefinition['route_name']; - } - - /** - * {@inheritdoc} - */ - public function getTitle() { - // Subclasses may pull in the request or specific attributes as parameters. - return $this->t($this->pluginDefinition['title']); - } - - /** - * {@inheritdoc} - * - * @todo update based on https://drupal.org/node/2045267 - */ - public function getPath() { - // Subclasses may set a request into the generator or use any desired method - // to generate the path. - $path = $this->generator->generate($this->getRouteName()); - // In order to get the Drupal path the base URL has to be stripped off. - $base_url = $this->generator->getContext()->getBaseUrl(); - if (!empty($base_url) && strpos($path, $base_url) === 0) { - $path = substr($path, strlen($base_url)); - } - return trim($path, '/'); - } - - /** - * Returns the weight of the local task. - * - * @return int - * The weight of the task. If not defined in the annotation returns 0 by - * default or -10 for the root tab. - */ - public function getWeight() { - // By default the weight is 0, or -10 for the root tab. - if (!isset($this->pluginDefinition['weight'])) { - if ($this->pluginDefinition['tab_root_id'] == $this->pluginDefinition['id']) { - $this->pluginDefinition['weight'] = -10; - } - else { - $this->pluginDefinition['weight'] = 0; - } - } - return (int) $this->pluginDefinition['weight']; - } - - /** - * {@inheritdoc} - */ - public function getOptions() { - $options = $this->pluginDefinition['options']; - if ($this->active) { - if (empty($options['attributes']['class']) || !in_array('active', $options['attributes']['class'])) { - $options['attributes']['class'][] = 'active'; - } - } - return (array) $options; - } - - /** - * {@inheritdoc} - */ - public function setActive($active = TRUE) { - $this->active = $active; - return $this; - } - - /** - * {@inheritdoc} - */ - public function getActive() { - return $this->active; - } - -} diff --git c/core/lib/Drupal/Core/Menu/LocalTaskManager.php w/core/lib/Drupal/Core/Menu/LocalTaskManager.php index a7bd6cf..17b5128 100644 --- c/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ w/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -7,14 +7,11 @@ namespace Drupal\Core\Menu; -use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; -use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator; -use Drupal\Core\Plugin\Discovery\YamlDiscovery; -use Drupal\Core\Plugin\Factory\ContainerFactory; use Drupal\Core\Routing\RouteProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; @@ -29,28 +26,6 @@ class LocalTaskManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $defaults = array( - // (required) The name of the route this task links to. - 'route_name' => '', - // The static title for the local task. - 'title' => '', - // The plugin ID of the root tab. - 'tab_root_id' => '', - // The plugin ID of the parent tab (or NULL for the top-level tab). - 'tab_parent_id' => NULL, - // The weight of the tab. - 'weight' => 0, - // The default link options. - 'options' => array(), - // Default class for local task implementations. - 'class' => 'Drupal\Core\Menu\LocalTaskDefault', - // The plugin id. Set by the plugin system and should never be provided in YAML. - 'id' => '', - ); - - /** * A controller resolver object. * * @var \Symfony\Component\HttpKernel\Controller\ControllerResolverInterface @@ -81,6 +56,9 @@ class LocalTaskManager extends DefaultPluginManager { /** * Constructs a \Drupal\Core\Menu\LocalTaskManager object. * + * @param \Traversable $namespaces + * An object that implements \Traversable which contains the root paths + * keyed by the corresponding namespace to look for plugin implementations, * @param \Symfony\Component\HttpKernel\Controller\ControllerResolverInterface $controller_resolver * An object to use in introspecting route methods. * @param \Symfony\Component\HttpFoundation\Request $request @@ -94,10 +72,8 @@ class LocalTaskManager extends DefaultPluginManager { * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. */ - public function __construct(ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager) { - $this->discovery = new YamlDiscovery('local_tasks', $module_handler->getModuleDirectories()); - $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery); - $this->factory = new ContainerFactory($this); + public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager) { + parent::__construct('Plugin/Menu/LocalTask', $namespaces, array(), 'Drupal\Core\Annotation\Menu\LocalTask'); $this->controllerResolver = $controller_resolver; $this->request = $request; $this->routeProvider = $route_provider; @@ -106,17 +82,6 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re } /** - * {@inheritdoc} - */ - public function processDefinition(&$definition, $plugin_id) { - parent::processDefinition($definition, $plugin_id); - // If there is no route name, this is a broken definition. - if (empty($definition['route_name'])) { - throw new PluginException(sprintf('Plugin (%s) definition must include "route_name"', $plugin_id)); - } - } - - /** * Gets the title for a local task. * * @param \Drupal\Core\Menu\LocalTaskInterface $local_task diff --git c/core/lib/Drupal/Core/Utility/LinkGenerator.php w/core/lib/Drupal/Core/Utility/LinkGenerator.php index 12dc3d6..c2a249c 100644 --- c/core/lib/Drupal/Core/Utility/LinkGenerator.php +++ w/core/lib/Drupal/Core/Utility/LinkGenerator.php @@ -74,13 +74,10 @@ public function __construct(UrlGeneratorInterface $url_generator, ModuleHandlerI public function setRequest(Request $request) { // Pre-calculate and store values based on the request that may be used // repeatedly in generate(). - $raw_variables = $request->attributes->get('_raw_variables'); - // $raw_variables is a ParameterBag object or NULL. - $parameters = $raw_variables ? $raw_variables->all() : array(); $this->active = array( 'route_name' => $request->attributes->get(RouteObjectInterface::ROUTE_NAME), 'language' => $this->languageManager->getLanguage(Language::TYPE_URL)->id, - 'parameters' => $parameters + (array) $request->query->all(), + 'parameters' => (array) $request->attributes->get('_raw_variables') + (array) $request->query->all(), ); } diff --git c/core/modules/action/lib/Drupal/action/Tests/ActionUninstallTest.php w/core/modules/action/lib/Drupal/action/Tests/ActionUninstallTest.php deleted file mode 100644 index 01b125d..0000000 --- c/core/modules/action/lib/Drupal/action/Tests/ActionUninstallTest.php +++ /dev/null @@ -1,52 +0,0 @@ - 'Uninstall action test', - 'description' => 'Tests that uninstalling actions does not remove other module\'s actions.', - 'group' => 'Action', - ); - } - - /** - * Tests Action uninstall. - */ - public function testActionUninstall() { - \Drupal::moduleHandler()->disable(array('action')); - \Drupal::moduleHandler()->uninstall(array('action')); - - $this->assertTrue(entity_load('action', 'user_block_user_action', TRUE), 'Configuration entity \'user_block_user_action\' still exists after uninstalling action module.' ); - - $admin_user = $this->drupalCreateUser(array('administer users')); - $this->drupalLogin($admin_user); - - $this->drupalGet('admin/people'); - // Ensure we have the user_block_user_action listed. - $this->assertRaw(''); - - } - -} diff --git c/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorFeedBlock.php w/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorFeedBlock.php index 04fc208..663bf5f 100644 --- c/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorFeedBlock.php +++ w/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorFeedBlock.php @@ -7,17 +7,14 @@ namespace Drupal\aggregator\Plugin\Derivative; -use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface; -use Drupal\Core\Database\Connection; -use Drupal\Core\StringTranslation\TranslationInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Component\Plugin\Derivative\DerivativeInterface; /** * Provides block plugin definitions for aggregator feeds. * * @see \Drupal\aggregator\Plugin\block\block\AggregatorFeedBlock */ -class AggregatorFeedBlock implements ContainerDerivativeInterface { +class AggregatorFeedBlock implements DerivativeInterface { /** * List of derivative definitions. @@ -27,88 +24,31 @@ class AggregatorFeedBlock implements ContainerDerivativeInterface { protected $derivatives = array(); /** - * The base plugin ID this derivative is for. - * - * @var string - */ - protected $basePluginId; - - /** - * The database connection. - * - * @var \Drupal\Core\Database\Connection - */ - protected $connection; - - /** - * The translation manager - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** - * Constructs a AggregatorFeedBlock object. - * - * @param string $base_plugin_id - * The base plugin ID. - * @param \Drupal\Core\Database\Connection $connection - * The database connection. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. - */ - public function __construct($base_plugin_id, Connection $connection, TranslationInterface $translation_manager) { - $this->basePluginId = $base_plugin_id; - $this->connection = $connection; - $this->translationManager = $translation_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, $base_plugin_id) { - return new static( - $base_plugin_id, - $container->get('database'), - $container->get('string_translation') - ); - } - - /** - * {@inheritdoc} + * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinition(). */ public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) { if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) { return $this->derivatives[$derivative_id]; } - $result = $this->connection->query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $derivative_id))->fetchObject(); + $result = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $derivative_id))->fetchObject(); $this->derivatives[$derivative_id] = $base_plugin_definition; $this->derivatives[$derivative_id]['delta'] = $result->fid; - $this->derivatives[$derivative_id]['admin_label'] = $this->t('@title feed latest items', array('@title' => $result->title)); + $this->derivatives[$derivative_id]['admin_label'] = t('@title feed latest items', array('@title' => $result->title)); return $this->derivatives[$derivative_id]; } /** - * {@inheritdoc} + * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinitions(). */ public function getDerivativeDefinitions(array $base_plugin_definition) { // Add a block plugin definition for each feed. - $result = $this->connection->query('SELECT fid, title FROM {aggregator_feed} WHERE block <> 0 ORDER BY fid'); + $result = db_query('SELECT fid, title FROM {aggregator_feed} WHERE block <> 0 ORDER BY fid'); foreach ($result as $feed) { $this->derivatives[$feed->fid] = $base_plugin_definition; $this->derivatives[$feed->fid]['delta'] = $feed->fid; - $this->derivatives[$feed->fid]['admin_label'] = $this->t('@title feed latest items', array('@title' => $feed->title)); + $this->derivatives[$feed->fid]['admin_label'] = t('@title feed latest items', array('@title' => $feed->title)); } return $this->derivatives; } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - } diff --git c/core/modules/comment/config/action.action.comment_publish_action.yml w/core/modules/comment/config/action.action.comment_publish_action.yml new file mode 100644 index 0000000..e29edfa --- /dev/null +++ w/core/modules/comment/config/action.action.comment_publish_action.yml @@ -0,0 +1,6 @@ +id: comment_publish_action +label: 'Publish comment' +status: '1' +langcode: en +type: comment +plugin: comment_publish_action diff --git c/core/modules/comment/config/action.action.comment_save_action.yml w/core/modules/comment/config/action.action.comment_save_action.yml new file mode 100644 index 0000000..47f8c39 --- /dev/null +++ w/core/modules/comment/config/action.action.comment_save_action.yml @@ -0,0 +1,6 @@ +id: comment_save_action +label: 'Save comment' +status: '1' +langcode: en +type: comment +plugin: comment_save_action diff --git c/core/modules/comment/config/action.action.comment_unpublish_action.yml w/core/modules/comment/config/action.action.comment_unpublish_action.yml new file mode 100644 index 0000000..0ac26fd --- /dev/null +++ w/core/modules/comment/config/action.action.comment_unpublish_action.yml @@ -0,0 +1,6 @@ +id: comment_unpublish_action +label: 'Unpublish comment' +status: '1' +langcode: en +type: comment +plugin: comment_unpublish_action diff --git c/core/modules/comment/config/system.action.comment_publish_action.yml w/core/modules/comment/config/system.action.comment_publish_action.yml deleted file mode 100644 index e29edfa..0000000 --- c/core/modules/comment/config/system.action.comment_publish_action.yml +++ /dev/null @@ -1,6 +0,0 @@ -id: comment_publish_action -label: 'Publish comment' -status: '1' -langcode: en -type: comment -plugin: comment_publish_action diff --git c/core/modules/comment/config/system.action.comment_save_action.yml w/core/modules/comment/config/system.action.comment_save_action.yml deleted file mode 100644 index 47f8c39..0000000 --- c/core/modules/comment/config/system.action.comment_save_action.yml +++ /dev/null @@ -1,6 +0,0 @@ -id: comment_save_action -label: 'Save comment' -status: '1' -langcode: en -type: comment -plugin: comment_save_action diff --git c/core/modules/comment/config/system.action.comment_unpublish_action.yml w/core/modules/comment/config/system.action.comment_unpublish_action.yml deleted file mode 100644 index 0ac26fd..0000000 --- c/core/modules/comment/config/system.action.comment_unpublish_action.yml +++ /dev/null @@ -1,6 +0,0 @@ -id: comment_unpublish_action -label: 'Unpublish comment' -status: '1' -langcode: en -type: comment -plugin: comment_unpublish_action diff --git c/core/modules/content_translation/content_translation.admin.inc w/core/modules/content_translation/content_translation.admin.inc index c5b8cfe..819a63b 100644 --- c/core/modules/content_translation/content_translation.admin.inc +++ w/core/modules/content_translation/content_translation.admin.inc @@ -470,10 +470,10 @@ function content_translation_translatable_batch($translatable, $field_name, &$co // We need a two-step approach while updating field translations: given // that field-specific update functions might rely on the stored values to - // perform their processing first we need to store the new translations - // and only after we can remove the old ones. Otherwise we might have data - // loss, since the removal of the old translations might occur before the - // new ones are stored. + // perform their processing, see for instance file_field_update(), first + // we need to store the new translations and only after we can remove the + // old ones. Otherwise we might have data loss, since the removal of the + // old translations might occur before the new ones are stored. if ($translatable && isset($entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED])) { // If the field is being switched to translatable and has data for // Language::LANGCODE_NOT_SPECIFIED then we need to move the data to the right diff --git c/core/modules/edit/edit.module w/core/modules/edit/edit.module index ae02deb..3fbf12f 100644 --- c/core/modules/edit/edit.module +++ w/core/modules/edit/edit.module @@ -55,7 +55,7 @@ function edit_permission() { * editing' permission. */ function edit_page_build(&$page) { - if (!Drupal::currentUser()->hasPermission('access in-place editing')) { + if (!user_access('access in-place editing')) { return; } diff --git c/core/modules/editor/lib/Drupal/editor/Plugin/InPlaceEditor/Editor.php w/core/modules/editor/lib/Drupal/editor/Plugin/InPlaceEditor/Editor.php index 4635053..1a4981a 100644 --- c/core/modules/editor/lib/Drupal/editor/Plugin/InPlaceEditor/Editor.php +++ w/core/modules/editor/lib/Drupal/editor/Plugin/InPlaceEditor/Editor.php @@ -68,7 +68,7 @@ protected function textFormatHasTransformationFilters($format_id) { * Implements \Drupal\edit\EditPluginInterface::getAttachments(). */ public function getAttachments() { - $user = \Drupal::currentUser(); + global $user; $user_format_ids = array_keys(filter_formats($user)); $manager = \Drupal::service('plugin.manager.editor'); diff --git c/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php w/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php index bdf0b3e..932f55f 100644 --- c/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php +++ w/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php @@ -88,8 +88,6 @@ public function testFieldAdminHandler() { $this->assertFieldByName('instance[settings][handler_settings][target_bundles][' . $bundle_name . ']'); } - reset($bundles); - // Test the sort settings. // Option 0: no sort. $this->assertFieldByName('instance[settings][handler_settings][sort][field]', '_none'); diff --git c/core/modules/field/field.purge.inc w/core/modules/field/field.purge.inc index 5ab55ef..e38f57f 100644 --- c/core/modules/field/field.purge.inc +++ w/core/modules/field/field.purge.inc @@ -78,13 +78,6 @@ function field_purge_batch($batch_size) { foreach ($instances as $instance) { $entity_type = $instance['entity_type']; - // We cannot purge anything if the entity type is unknown (e.g. the - // providing module was uninstalled). - // @todo Revisit after https://drupal.org/node/2080823. - if (!isset($info[$entity_type])) { - continue; - } - // EntityFieldQuery currently fails on conditions on comment bundle. // Remove when http://drupal.org/node/731724 is fixed. if ($entity_type == 'comment') { @@ -124,14 +117,6 @@ function field_purge_batch($batch_size) { $deleted_fields = Drupal::state()->get('field.field.deleted') ?: array(); foreach ($deleted_fields as $field) { $field = new Field($field); - - // We cannot purge anything if the entity type is unknown (e.g. the - // providing module was uninstalled). - // @todo Revisit after https://drupal.org/node/2080823. - if (!isset($info[$field->entity_type])) { - continue; - } - $instances = field_read_instances(array('field_id' => $field['uuid']), array('include_deleted' => 1)); if (empty($instances)) { field_purge_field($field); diff --git c/core/modules/file/file.field.inc w/core/modules/file/file.field.inc index 320f5dc..a40a44b 100644 --- c/core/modules/file/file.field.inc +++ w/core/modules/file/file.field.inc @@ -6,15 +6,314 @@ */ use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Entity\EntityInterface; /** - * Implements hook_field_info_alter(). + * Implements hook_field_info(). + */ +function file_field_info() { + return array( + 'file' => array( + 'label' => t('File'), + 'description' => t('This field stores the ID of a file as an integer value.'), + 'settings' => array( + 'display_field' => 0, + 'display_default' => 0, + 'uri_scheme' => file_default_scheme(), + ), + 'instance_settings' => array( + 'file_extensions' => 'txt', + 'file_directory' => '', + 'max_filesize' => '', + 'description_field' => 0, + ), + 'default_widget' => 'file_generic', + 'default_formatter' => 'file_default', + 'class' => '\Drupal\file\Type\FileItem', + 'list_class' => '\Drupal\file\Type\FileField', + ), + ); +} + +/** + * Implements hook_field_settings_form(). + */ +function file_field_settings_form($field, $instance) { + $defaults = \Drupal::service('plugin.manager.entity.field.field_type')->getDefaultSettings($field['type']); + $settings = array_merge($defaults, $field['settings']); + + $form['#attached']['library'][] = array('file', 'drupal.file'); + + $form['display_field'] = array( + '#type' => 'checkbox', + '#title' => t('Enable Display field'), + '#default_value' => $settings['display_field'], + '#description' => t('The display option allows users to choose if a file should be shown when viewing the content.'), + ); + $form['display_default'] = array( + '#type' => 'checkbox', + '#title' => t('Files displayed by default'), + '#default_value' => $settings['display_default'], + '#description' => t('This setting only has an effect if the display option is enabled.'), + '#states' => array( + 'visible' => array( + ':input[name="field[settings][display_field]"]' => array('checked' => TRUE), + ), + ), + ); + + $scheme_options = array(); + foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { + $scheme_options[$scheme] = $stream_wrapper['name']; + } + $form['uri_scheme'] = array( + '#type' => 'radios', + '#title' => t('Upload destination'), + '#options' => $scheme_options, + '#default_value' => $settings['uri_scheme'], + '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), + '#disabled' => $field->hasData(), + ); + + return $form; +} + +/** + * Implements hook_field_instance_settings_form(). + */ +function file_field_instance_settings_form($field, $instance) { + $settings = $instance['settings']; + + $form['file_directory'] = array( + '#type' => 'textfield', + '#title' => t('File directory'), + '#default_value' => $settings['file_directory'], + '#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'), + '#element_validate' => array('_file_generic_settings_file_directory_validate'), + '#weight' => 3, + ); + + // Make the extension list a little more human-friendly by comma-separation. + $extensions = str_replace(' ', ', ', $settings['file_extensions']); + $form['file_extensions'] = array( + '#type' => 'textfield', + '#title' => t('Allowed file extensions'), + '#default_value' => $extensions, + '#description' => t('Separate extensions with a space or comma and do not include the leading dot.'), + '#element_validate' => array('_file_generic_settings_extensions'), + '#weight' => 1, + // By making this field required, we prevent a potential security issue + // that would allow files of any type to be uploaded. + '#required' => TRUE, + ); + + $form['max_filesize'] = array( + '#type' => 'textfield', + '#title' => t('Maximum upload size'), + '#default_value' => $settings['max_filesize'], + '#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit %limit).', array('%limit' => format_size(file_upload_max_size()))), + '#size' => 10, + '#element_validate' => array('_file_generic_settings_max_filesize'), + '#weight' => 5, + ); + + $form['description_field'] = array( + '#type' => 'checkbox', + '#title' => t('Enable Description field'), + '#default_value' => isset($settings['description_field']) ? $settings['description_field'] : '', + '#description' => t('The description field allows users to enter a description about the uploaded file.'), + '#parents' => array('instance', 'settings', 'description_field'), + '#weight' => 11, + ); + + return $form; +} + +/** + * Render API callback: Validates the maximum upload size field. + * + * Ensures that a size has been entered and that it can be parsed by + * parse_size(). + * + * This function is assigned as an #element_validate callback in + * file_field_instance_settings_form(). + */ +function _file_generic_settings_max_filesize($element, &$form_state) { + if (!empty($element['#value']) && !is_numeric(parse_size($element['#value']))) { + form_error($element, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title'])))); + } +} + +/** + * Render API callback: Validates the allowed file extensions field. + * + * This function is assigned as an #element_validate callback in + * file_field_instance_settings_form(). + * + * This doubles as a convenience clean-up function and a validation routine. + * Commas are allowed by the end-user, but ultimately the value will be stored + * as a space-separated list for compatibility with file_validate_extensions(). + */ +function _file_generic_settings_extensions($element, &$form_state) { + if (!empty($element['#value'])) { + $extensions = preg_replace('/([, ]+\.?)/', ' ', trim(strtolower($element['#value']))); + $extensions = array_filter(explode(' ', $extensions)); + $extensions = implode(' ', array_unique($extensions)); + if (!preg_match('/^([a-z0-9]+([.][a-z0-9])* ?)+$/', $extensions)) { + form_error($element, t('The list of allowed extensions is not valid, be sure to exclude leading dots and to separate extensions with a comma or space.')); + } + else { + form_set_value($element, $extensions, $form_state); + } + } +} + +/** + * Render API callback: Validates the file destination field. + * + * Removes slashes from the beginning and end of the destination value and + * ensures that the file directory path is not included at the beginning of the + * value. + * + * This function is assigned as an #element_validate callback in + * file_field_instance_settings_form(). + */ +function _file_generic_settings_file_directory_validate($element, &$form_state) { + // Strip slashes from the beginning and end of $widget['file_directory']. + $value = trim($element['#value'], '\\/'); + form_set_value($element, $value, $form_state); +} + +/** + * Implements hook_field_insert(). + */ +function file_field_insert(EntityInterface $entity, $field, $instance, $langcode, &$items) { + // Add a new usage of each uploaded file. + foreach ($items as $item) { + file_usage()->add(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); + } +} + +/** + * Implements hook_field_update(). * - * Cannot annotate in FieldItem plugin the settings.uri_scheme meta data key - * with a dynamic value. We need to alter the value here. + * Checks for files that have been removed from the object. + */ +function file_field_update(EntityInterface $entity, $field, $instance, $langcode, &$items) { + // On new revisions, all files are considered to be a new usage and no + // deletion of previous file usages are necessary. + if (!empty($entity->original) && $entity->getRevisionId() != $entity->original->getRevisionId()) { + foreach ($items as $item) { + file_usage()->add(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); + } + return; + } + + // Build a display of the current FIDs. + $current_fids = array(); + foreach ($items as $item) { + $current_fids[] = $item['target_id']; + } + + // Compare the original field values with the ones that are being saved. + $original = $entity->original->getBCEntity(); + $original_fids = array(); + if (!empty($original->{$field['field_name']}[$langcode])) { + foreach ($original->{$field['field_name']}[$langcode] as $original_item) { + $original_fids[] = $original_item['target_id']; + if (isset($original_item['target_id']) && !in_array($original_item['target_id'], $current_fids)) { + // Decrement the file usage count by 1. + file_usage()->delete(file_load($original_item['target_id']), 'file', $entity->entityType(), $entity->id()); + } + } + } + + // Add new usage entries for newly added files. + foreach ($items as $item) { + if (!in_array($item['target_id'], $original_fids)) { + file_usage()->add(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); + } + } +} + +/** + * Implements hook_field_delete(). */ -function file_field_info_alter(&$info) { - $info['file']['settings']['uri_scheme'] = file_default_scheme(); +function file_field_delete(EntityInterface $entity, $field, $instance, $langcode, &$items) { + // Delete all file usages within this entity. + foreach ($items as $delta => $item) { + file_usage()->delete(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id(), 0); + } +} + +/** + * Implements hook_field_delete_revision(). + */ +function file_field_delete_revision(EntityInterface $entity, $field, $instance, $langcode, &$items) { + foreach ($items as $delta => $item) { + // Decrement the file usage count by 1. + file_usage()->delete(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); + } +} + +/** + * Implements hook_field_is_empty(). + */ +function file_field_is_empty($item, $field_type) { + return empty($item['target_id']); +} + +/** + * Retrieves the upload validators for a file field. + * + * @param array $field_settings + * The field settings. + * + * @return + * An array suitable for passing to file_save_upload() or the file field + * element's '#upload_validators' property. + */ +function file_field_widget_upload_validators(array $field_settings) { + // Cap the upload size according to the PHP limit. + $max_filesize = parse_size(file_upload_max_size()); + if (!empty($field_settings['max_filesize']) && parse_size($field_settings['max_filesize']) < $max_filesize) { + $max_filesize = parse_size($field_settings['max_filesize']); + } + + $validators = array(); + + // There is always a file size limit due to the PHP server limit. + $validators['file_validate_size'] = array($max_filesize); + + // Add the extension check if necessary. + if (!empty($field_settings['file_extensions'])) { + $validators['file_validate_extensions'] = array($field_settings['file_extensions']); + } + + return $validators; +} + +/** + * Determines the URI for a file field. + * + * @param array $field_settings + * The field settings. + * @param $data + * An array of token objects to pass to + * \Drupal\Core\Utility\Token::replace(). + * + * @return + * A file directory URI with tokens replaced. + * + * @see \Drupal\Core\Utility\Token::replace() + */ +function file_field_widget_uri(array $field_settings, $data = array()) { + $destination = trim($field_settings['file_directory'], '/'); + + // Replace tokens. + $destination = Drupal::token()->replace($destination, $data); + + return $field_settings['uri_scheme'] . '://' . $destination; } /** diff --git c/core/modules/file/file.install w/core/modules/file/file.install index 33717c2..2a958eb 100644 --- c/core/modules/file/file.install +++ w/core/modules/file/file.install @@ -153,6 +153,44 @@ function file_schema() { } /** + * Implements hook_field_schema(). + */ +function file_field_schema($field) { + return array( + 'columns' => array( + 'target_id' => array( + 'description' => 'The ID of the target entity.', + 'type' => 'int', + 'not null' => TRUE, + 'unsigned' => TRUE, + ), + 'display' => array( + 'description' => 'Flag to control whether this file should be displayed when viewing content.', + 'type' => 'int', + 'size' => 'tiny', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 1, + ), + 'description' => array( + 'description' => 'A description of the file.', + 'type' => 'text', + 'not null' => FALSE, + ), + ), + 'indexes' => array( + 'target_id' => array('target_id'), + ), + 'foreign keys' => array( + 'target_id' => array( + 'table' => 'file_managed', + 'columns' => array('target_id' => 'fid'), + ), + ), + ); +} + +/** * Implements hook_requirements(). * * Display information about getting upload progress bars working. diff --git c/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileField.php w/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileField.php deleted file mode 100644 index 9483fd1..0000000 --- c/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileField.php +++ /dev/null @@ -1,71 +0,0 @@ -updateFileUsage(); - } - - /** - * Updates the file usage. - */ - protected function updateFileUsage() { - $entity = $this->getRoot(); - - // On new revisions, all files are considered to be a new usage and no - // deletion of previous file usages are necessary. - if (!empty($entity->original) && $entity->getRevisionId() != $entity->original->getRevisionId()) { - foreach ($this->list as $item) { - file_usage()->add($item->entity, 'file', $entity->entityType(), $entity->id()); - } - return; - } - - // Build a list of the current target IDs. - $fids = array(); - foreach ($this->list as $item) { - $fids[] = $item->target_id; - } - - // Compare the original field values with the ones that are being saved. - $field_name = $this->getFieldDefinition()->getFieldName(); - $original_fids = array(); - $original_items = $entity->original->getTranslation($this->getLangcode())->$field_name; - foreach ($original_items as $item) { - $original_fids[] = $item->target_id; - if ($item->target_id && !in_array($item->target_id, $fids)) { - // Decrement the file usage count by 1. - file_usage()->delete($item->entity, 'file', $entity->entityType(), $entity->id()); - } - } - - // Add new usage entries for newly added files. - foreach ($this->list as $item) { - if ($item->target_id && !in_array($item->target_id, $original_fids)) { - file_usage()->add($item->entity, 'file', $entity->entityType(), $entity->id()); - } - } - } - -} diff --git c/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php w/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php deleted file mode 100644 index 5de9a76..0000000 --- c/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php +++ /dev/null @@ -1,357 +0,0 @@ -instance) && $parent = $this->getParent()) { - $this->instance = $parent->getInstance(); - } - return $this->instance; - } - - /** - * {@inheritdoc} - */ - public static function schema(FieldInterface $field) { - return array( - 'columns' => array( - 'target_id' => array( - 'description' => 'The ID of the file entity.', - 'type' => 'int', - 'not null' => TRUE, - 'unsigned' => TRUE, - ), - 'display' => array( - 'description' => 'Flag to control whether this file should be displayed when viewing content.', - 'type' => 'int', - 'size' => 'tiny', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 1, - ), - 'description' => array( - 'description' => 'A description of the file.', - 'type' => 'text', - 'not null' => FALSE, - ), - ), - 'indexes' => array( - 'target_id' => array('target_id'), - ), - 'foreign keys' => array( - 'target_id' => array( - 'table' => 'file_managed', - 'columns' => array('target_id' => 'fid'), - ), - ), - ); - } - - /** - * {@inheritdoc} - */ - public function getPropertyDefinitions() { - $this->definition['settings']['target_type'] = 'file'; - - if (!isset(static::$propertyDefinitions)) { - static::$propertyDefinitions = parent::getPropertyDefinitions(); - - static::$propertyDefinitions['display'] = array( - 'type' => 'boolean', - 'label' => t('Flag to control whether this file should be displayed when viewing content.'), - ); - static::$propertyDefinitions['description'] = array( - 'type' => 'string', - 'label' => t('A description of the file.'), - ); - } - return static::$propertyDefinitions; - } - - /** - * {@inheritdoc} - */ - public function settingsForm(array $form, array &$form_state, $has_data) { - $element = array(); - - $element['#attached']['library'][] = array('file', 'drupal.file'); - - $element['display_field'] = array( - '#type' => 'checkbox', - '#title' => t('Enable Display field'), - '#default_value' => $this->getFieldSetting('display_field'), - '#description' => t('The display option allows users to choose if a file should be shown when viewing the content.'), - ); - $element['display_default'] = array( - '#type' => 'checkbox', - '#title' => t('Files displayed by default'), - '#default_value' => $this->getFieldSetting('display_default'), - '#description' => t('This setting only has an effect if the display option is enabled.'), - '#states' => array( - 'visible' => array( - ':input[name="field[settings][display_field]"]' => array('checked' => TRUE), - ), - ), - ); - - $scheme_options = array(); - foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { - $scheme_options[$scheme] = $stream_wrapper['name']; - } - $element['uri_scheme'] = array( - '#type' => 'radios', - '#title' => t('Upload destination'), - '#options' => $scheme_options, - '#default_value' => $this->getFieldSetting('uri_scheme'), - '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), - '#disabled' => $has_data, - ); - - return $element; - } - - /** - * {@inheritdoc} - */ - public function instanceSettingsForm(array $form, array &$form_state) { - $element = array(); - $settings = $this->getFieldSettings(); - - $element['file_directory'] = array( - '#type' => 'textfield', - '#title' => t('File directory'), - '#default_value' => $settings['file_directory'], - '#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'), - '#element_validate' => array(array(get_class($this), 'validateDirectory')), - '#weight' => 3, - ); - - // Make the extension list a little more human-friendly by comma-separation. - $extensions = str_replace(' ', ', ', $settings['file_extensions']); - $element['file_extensions'] = array( - '#type' => 'textfield', - '#title' => t('Allowed file extensions'), - '#default_value' => $extensions, - '#description' => t('Separate extensions with a space or comma and do not include the leading dot.'), - '#element_validate' => array(array(get_class($this), 'validateExtensions')), - '#weight' => 1, - // By making this field required, we prevent a potential security issue - // that would allow files of any type to be uploaded. - '#required' => TRUE, - ); - - $element['max_filesize'] = array( - '#type' => 'textfield', - '#title' => t('Maximum upload size'), - '#default_value' => $settings['max_filesize'], - '#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit %limit).', array('%limit' => format_size(file_upload_max_size()))), - '#size' => 10, - '#element_validate' => array(array(get_class($this), 'validateMaxFilesize')), - '#weight' => 5, - ); - - $element['description_field'] = array( - '#type' => 'checkbox', - '#title' => t('Enable Description field'), - '#default_value' => isset($settings['description_field']) ? $settings['description_field'] : '', - '#description' => t('The description field allows users to enter a description about the uploaded file.'), - '#parents' => array('instance', 'settings', 'description_field'), - '#weight' => 11, - ); - - return $element; - } - - /** - * {@inheritdoc} - */ - public function insert() { - // @todo Move in FileField in https://drupal.org/node/2073033. - $entity = $this->getRoot(); - - // Add a new usage for this new uploaded file. - file_usage()->add($this->entity, 'file', $entity->entityType(), $entity->id()); - } - - /** - * {@inheritdoc} - */ - public function delete() { - // @todo Move in FileField in https://drupal.org/node/2073033. - $entity = $this->getRoot(); - - // Delete all file usages within this entity. - file_usage()->delete($this->entity, 'file', $entity->entityType(), $entity->id(), 0); - } - - /** - * {@inheritdoc} - */ - public function deleteRevision() { - // @todo Move in FileField in https://drupal.org/node/2073033. - $entity = $this->getRoot(); - - // Decrement the file usage count by 1. - file_usage()->delete($this->entity, 'file', $entity->entityType(), $entity->id()); - } - - /** - * {@inheritdoc} - */ - public function isEmpty() { - return empty($this->target_id); - } - - /** - * Form API callback - * - * Removes slashes from the beginning and end of the destination value and - * ensures that the file directory path is not included at the beginning of the - * value. - * - * This function is assigned as an #element_validate callback in - * instanceSettingsForm(). - */ - public static function validateDirectory($element, &$form_state) { - // Strip slashes from the beginning and end of $element['file_directory']. - $value = trim($element['#value'], '\\/'); - form_set_value($element, $value, $form_state); - } - - /** - * Form API callback. - * - * This function is assigned as an #element_validate callback in - * instanceSettingsForm(). - * - * This doubles as a convenience clean-up function and a validation routine. - * Commas are allowed by the end-user, but ultimately the value will be stored - * as a space-separated list for compatibility with file_validate_extensions(). - */ - public static function validateExtensions($element, &$form_state) { - if (!empty($element['#value'])) { - $extensions = preg_replace('/([, ]+\.?)/', ' ', trim(strtolower($element['#value']))); - $extensions = array_filter(explode(' ', $extensions)); - $extensions = implode(' ', array_unique($extensions)); - if (!preg_match('/^([a-z0-9]+([.][a-z0-9])* ?)+$/', $extensions)) { - form_error($element, t('The list of allowed extensions is not valid, be sure to exclude leading dots and to separate extensions with a comma or space.')); - } - else { - form_set_value($element, $extensions, $form_state); - } - } - } - - /** - * Form API callback. - * - * Ensures that a size has been entered and that it can be parsed by - * parse_size(). - * - * This function is assigned as an #element_validate callback in - * instanceSettingsForm(). - */ - public static function validateMaxFilesize($element, &$form_state) { - if (!empty($element['#value']) && !is_numeric(parse_size($element['#value']))) { - form_error($element, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title'])))); - } - } - - /** - * Determines the URI for a file field instance. - * - * @param $data - * An array of token objects to pass to token_replace(). - * - * @return - * A file directory URI with tokens replaced. - * - * @see token_replace() - */ - public function getUploadLocation($data = array()) { - $settings = $this->getFieldSettings(); - $destination = trim($settings['file_directory'], '/'); - - // Replace tokens. - $destination = \Drupal::token()->replace($destination, $data); - - return $settings['uri_scheme'] . '://' . $destination; - } - - /** - * Retrieves the upload validators for a file field. - * - * @return - * An array suitable for passing to file_save_upload() or the file field - * element's '#upload_validators' property. - */ - public function getUploadValidators() { - $validators = array(); - $settings = $this->getFieldSettings(); - - // Cap the upload size according to the PHP limit. - $max_filesize = parse_size(file_upload_max_size()); - if (!empty($settings['max_filesize'])) { - $max_filesize = min($max_filesize, parse_size($settings['max_filesize'])); - } - - // There is always a file size limit due to the PHP server limit. - $validators['file_validate_size'] = array($max_filesize); - - // Add the extension check if necessary. - if (!empty($settings['file_extensions'])) { - $validators['file_validate_extensions'] = array($settings['file_extensions']); - } - - return $validators; - } - -} diff --git c/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php w/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php index 97e677c..1e12c5b 100644 --- c/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php +++ w/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php @@ -180,6 +180,8 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang // The field settings include defaults for the field type. However, this // widget is a base class for other widgets (e.g., ImageWidget) that may act // on field types without these expected settings. + // @todo Add support for merging settings of base types to implementations + // of FieldDefinitionInterface::getFieldSettings(). $field_settings += array( 'display_default' => NULL, 'display_field' => NULL, @@ -198,8 +200,8 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang $element_info = element_info('managed_file'); $element += array( '#type' => 'managed_file', - '#upload_location' => $items[$delta]->getUploadLocation(), - '#upload_validators' => $items[$delta]->getUploadValidators(), + '#upload_location' => file_field_widget_uri($field_settings), + '#upload_validators' => file_field_widget_upload_validators($field_settings), '#value_callback' => 'file_field_widget_value', '#process' => array_merge($element_info['#process'], array('file_field_widget_process')), '#progress_indicator' => $this->getSetting('progress_indicator'), diff --git c/core/modules/file/lib/Drupal/file/Type/FileField.php w/core/modules/file/lib/Drupal/file/Type/FileField.php new file mode 100644 index 0000000..3666238 --- /dev/null +++ w/core/modules/file/lib/Drupal/file/Type/FileField.php @@ -0,0 +1,22 @@ +definition['settings']['target_type'] = 'file'; + // Definitions vary by entity type and bundle, so key them accordingly. + $key = $this->definition['settings']['target_type'] . ':'; + $key .= isset($this->definition['settings']['target_bundle']) ? $this->definition['settings']['target_bundle'] : ''; + + if (!isset(static::$propertyDefinitions[$key])) { + static::$propertyDefinitions[$key] = parent::getPropertyDefinitions(); + + static::$propertyDefinitions[$key]['display'] = array( + 'type' => 'boolean', + 'label' => t('Flag to control whether this file should be displayed when viewing content.'), + ); + static::$propertyDefinitions[$key]['description'] = array( + 'type' => 'string', + 'label' => t('A description of the file.'), + ); + } + return static::$propertyDefinitions[$key]; + } + +} diff --git c/core/modules/image/image.field.inc w/core/modules/image/image.field.inc index 4b1118d..c682747 100644 --- c/core/modules/image/image.field.inc +++ w/core/modules/image/image.field.inc @@ -6,12 +6,273 @@ */ use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Entity\EntityInterface; /** - * Implements hook_field_info_alter(). + * Implements hook_field_info(). */ -function image_field_info_alter(&$info) { - $info['image']['settings']['uri_scheme'] = file_default_scheme(); +function image_field_info() { + return array( + 'image' => array( + 'label' => t('Image'), + 'description' => t('This field stores the ID of an image file as an integer value.'), + 'settings' => array( + 'uri_scheme' => file_default_scheme(), + 'default_image' => 0, + 'column_groups' => array( + 'file' => array( + 'label' => t('File'), + 'columns' => array('target_id', 'width', 'height'), + ), + 'alt' => array( + 'label' => t('Alt'), + 'translatable' => TRUE, + ), + 'title' => array( + 'label' => t('Title'), + 'translatable' => TRUE, + ), + ), + ), + 'instance_settings' => array( + 'file_extensions' => 'png gif jpg jpeg', + 'file_directory' => '', + 'max_filesize' => '', + 'alt_field' => 0, + 'alt_field_required' => 0, + 'title_field' => 0, + 'title_field_required' => 0, + 'max_resolution' => '', + 'min_resolution' => '', + 'default_image' => 0, + ), + 'default_widget' => 'image_image', + 'default_formatter' => 'image', + 'class' => '\Drupal\image\Type\ImageItem', + 'list_class' => '\Drupal\image\Type\ImageField', + ), + ); +} + +/** + * Implements hook_field_settings_form(). + */ +function image_field_settings_form($field, $instance) { + $defaults = \Drupal::service('plugin.manager.entity.field.field_type')->getDefaultSettings($field['type']); + $settings = array_merge($defaults, $field['settings']); + + $scheme_options = array(); + foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { + $scheme_options[$scheme] = $stream_wrapper['name']; + } + $form['uri_scheme'] = array( + '#type' => 'radios', + '#title' => t('Upload destination'), + '#options' => $scheme_options, + '#default_value' => $settings['uri_scheme'], + '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), + ); + + // When the user sets the scheme on the UI, even for the first time, it's + // updating a field because fields are created on the "Manage fields" + // page. So image_field_update_field() can handle this change. + $form['default_image'] = array( + '#title' => t('Default image'), + '#type' => 'managed_file', + '#description' => t('If no image is uploaded, this image will be shown on display.'), + '#default_value' => empty($field['settings']['default_image']) ? array() : array($field['settings']['default_image']), + '#upload_location' => $settings['uri_scheme'] . '://default_images/', + ); + + return $form; +} + +/** + * Implements hook_field_instance_settings_form(). + */ +function image_field_instance_settings_form($field, $instance) { + $settings = $instance['settings']; + + // Use the file field instance settings form as a basis. + $form = file_field_instance_settings_form($field, $instance); + + // Add maximum and minimum resolution settings. + $max_resolution = explode('x', $settings['max_resolution']) + array('', ''); + $form['max_resolution'] = array( + '#type' => 'item', + '#title' => t('Maximum image resolution'), + '#element_validate' => array('_image_field_resolution_validate'), + '#weight' => 4.1, + '#field_prefix' => '
$value
\n"); - $this->assertEqual($entity->summary_field->summary_processed, "$summary
\n"); - - // Change the format, this should update the processed properties. - $entity->summary_field->format = 'no_filters'; - $this->assertEqual($entity->summary_field->processed, $value); - $this->assertEqual($entity->summary_field->summary_processed, $summary); - } - - /** - * Tests that the processed values are cached. - */ - function testProcessedCache() { - // Use an entity type that has caching enabled. - $entity_type = 'entity_test_rev'; - - $this->createField($entity_type); - - // Create an entity with a summary and a text format. - $entity = entity_create($entity_type, array()); - $entity->summary_field->value = $value = $this->randomName(); - $entity->summary_field->summary = $summary = $this->randomName(); - $entity->summary_field->format = 'plain_text'; - $entity->name->value = $this->randomName(); - $entity->save(); - - // Inject values into the cache to make sure that these are used as-is and - // not re-calculated. - $data = array( - 'summary_field' => array( - Language::LANGCODE_DEFAULT => array( - 0 => array( - 'value' => $value, - 'summary' => $summary, - 'format' => 'plain_text', - 'processed' => 'Cached processed value', - 'summary_processed' => 'Cached summary processed value', - ), - ), - ), - ); - cache('field')->set("field:$entity_type:" . $entity->id(), $data); - - $entity = entity_load($entity_type, $entity->id()); - $this->assertEqual($entity->summary_field->processed, 'Cached processed value'); - $this->assertEqual($entity->summary_field->summary_processed, 'Cached summary processed value'); - - // Change the format, this should update the processed properties. - $entity->summary_field->format = 'no_filters'; - $this->assertEqual($entity->summary_field->processed, $value); - $this->assertEqual($entity->summary_field->summary_processed, $summary); - } - - /** - * Creates a text_with_summary field and field instance. - * - * @param string $entity_type - * Entity type for which the field should be created. - */ - protected function createField($entity_type) { - // Create a field . - $this->field = entity_create('field_entity', array( - 'name' => 'summary_field', - 'entity_type' => $entity_type, - 'type' => 'text_with_summary', - 'settings' => array( - 'max_length' => 10, - ) - )); - $this->field->save(); - $this->instance = entity_create('field_instance', array( - 'field_name' => $this->field->name, - 'entity_type' => $entity_type, - 'bundle' => $entity_type, - 'settings' => array( - 'text_processing' => 0, - ) - )); - $this->instance->save(); - } - -} diff --git c/core/modules/text/lib/Drupal/text/TextProcessed.php w/core/modules/text/lib/Drupal/text/TextProcessed.php index c7a9215..352420d 100644 --- c/core/modules/text/lib/Drupal/text/TextProcessed.php +++ w/core/modules/text/lib/Drupal/text/TextProcessed.php @@ -21,11 +21,18 @@ class TextProcessed extends TypedData { /** - * Cached processed text. + * The text property. * - * @var string|null + * @var \Drupal\Core\TypedData\TypedDataInterface */ - protected $processed = NULL; + protected $text; + + /** + * The text format property. + * + * @var \Drupal\Core\TypedData\TypedDataInterface + */ + protected $format; /** * Overrides TypedData::__construct(). @@ -39,34 +46,46 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface } /** + * Overrides TypedData::setContext(). + */ + public function setContext($name = NULL, TypedDataInterface $parent = NULL) { + parent::setContext($name, $parent); + if (isset($parent)) { + $this->text = $parent->get($this->definition['settings']['text source']); + $this->format = $parent->get('format'); + } + } + + /** * Implements \Drupal\Core\TypedData\TypedDataInterface::getValue(). */ public function getValue($langcode = NULL) { - if ($this->processed !== NULL) { - return $this->processed; + + if (!isset($this->text)) { + throw new InvalidArgumentException('Computed properties require context for computation.'); } - $item = $this->getParent(); - $text = $item->{($this->definition['settings']['text source'])}; - if ($item->getFieldDefinition()->getFieldSetting('text_processing')) { - $this->processed = check_markup($text, $item->format, $item->getLangcode()); + $field = $this->parent->getParent(); + $entity = $field->getParent(); + $instance = field_info_instance($entity->entityType(), $field->getName(), $entity->bundle()); + + if (!empty($instance['settings']['text_processing']) && $this->format->getValue()) { + return check_markup($this->text->getValue(), $this->format->getValue(), $entity->language()->id); } else { - // Escape all HTML and retain newlines. - // @see \Drupal\text\Plugin\field\formatter\TextPlainFormatter - $this->processed = nl2br(check_plain($text)); + // If no format is available, still make sure to sanitize the text. + return check_plain($this->text->getValue()); } - return $this->processed; } /** * Implements \Drupal\Core\TypedData\TypedDataInterface::setValue(). */ public function setValue($value, $notify = TRUE) { - $this->processed = $value; - // Notify the parent of any changes. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); + if (isset($value)) { + // @todo This is triggered from DatabaseStorageController::invokeFieldMethod() + // in the case of case of non-NG entity types. + // throw new ReadOnlyException('Unable to set a computed property.'); } } diff --git c/core/modules/text/text.module w/core/modules/text/text.module index ecc0767..9014113 100644 --- c/core/modules/text/text.module +++ w/core/modules/text/text.module @@ -41,6 +41,42 @@ function text_help($path, $arg) { } /** + * Sanitizes the 'value' or 'summary' data of a text value. + * + * Depending on whether the field instance uses text processing, data is run + * through check_plain() or check_markup(). + * + * @param bool $text_processing + * Whether to process the text via check_markup(). + * @param string $langcode + * The language associated with $item. + * @param array $item + * The field value to sanitize. + * @param string $column + * The column to sanitize (either 'value' or 'summary'). + * + * @return string + * The sanitized string. + */ +function text_sanitize($text_processing, $langcode, $item, $column) { + if (isset($item["safe_$column"])) { + return $item["safe_$column"]; + } + + // Optimize by opting out for the trivial 'empty string' case. + if ($item[$column] == '') { + return ''; + } + + if ($text_processing) { + return check_markup($item[$column], $item['format'], $langcode); + } + // Escape all HTML and retain newlines. + // @see \Drupal\text\Plugin\field\formatter\TextPlainFormatter + return nl2br(check_plain($item[$column])); +} + +/** * Generates a trimmed, formatted version of a text field value. * * If the end of the summary is not indicated using the delimiter diff --git c/core/modules/user/config/action.action.user_block_user_action.yml w/core/modules/user/config/action.action.user_block_user_action.yml new file mode 100644 index 0000000..2c4ed88 --- /dev/null +++ w/core/modules/user/config/action.action.user_block_user_action.yml @@ -0,0 +1,6 @@ +id: user_block_user_action +label: 'Block the selected user(s)' +status: '1' +langcode: en +type: user +plugin: user_block_user_action diff --git c/core/modules/user/config/action.action.user_cancel_user_action.yml w/core/modules/user/config/action.action.user_cancel_user_action.yml new file mode 100644 index 0000000..b69d2d9 --- /dev/null +++ w/core/modules/user/config/action.action.user_cancel_user_action.yml @@ -0,0 +1,6 @@ +id: user_cancel_user_action +label: 'Cancel the selected user account(s)' +status: '1' +langcode: en +type: user +plugin: user_cancel_user_action diff --git c/core/modules/user/config/action.action.user_unblock_user_action.yml w/core/modules/user/config/action.action.user_unblock_user_action.yml new file mode 100644 index 0000000..20a6fd5 --- /dev/null +++ w/core/modules/user/config/action.action.user_unblock_user_action.yml @@ -0,0 +1,6 @@ +id: user_unblock_user_action +label: 'Unblock the selected user(s)' +status: '1' +langcode: en +type: user +plugin: user_unblock_user_action diff --git c/core/modules/user/config/system.action.user_block_user_action.yml w/core/modules/user/config/system.action.user_block_user_action.yml deleted file mode 100644 index 2c4ed88..0000000 --- c/core/modules/user/config/system.action.user_block_user_action.yml +++ /dev/null @@ -1,6 +0,0 @@ -id: user_block_user_action -label: 'Block the selected user(s)' -status: '1' -langcode: en -type: user -plugin: user_block_user_action diff --git c/core/modules/user/config/system.action.user_cancel_user_action.yml w/core/modules/user/config/system.action.user_cancel_user_action.yml deleted file mode 100644 index b69d2d9..0000000 --- c/core/modules/user/config/system.action.user_cancel_user_action.yml +++ /dev/null @@ -1,6 +0,0 @@ -id: user_cancel_user_action -label: 'Cancel the selected user account(s)' -status: '1' -langcode: en -type: user -plugin: user_cancel_user_action diff --git c/core/modules/user/config/system.action.user_unblock_user_action.yml w/core/modules/user/config/system.action.user_unblock_user_action.yml deleted file mode 100644 index 20a6fd5..0000000 --- c/core/modules/user/config/system.action.user_unblock_user_action.yml +++ /dev/null @@ -1,6 +0,0 @@ -id: user_unblock_user_action -label: 'Unblock the selected user(s)' -status: '1' -langcode: en -type: user -plugin: user_unblock_user_action diff --git c/core/modules/views/templates/views-mini-pager.html.twig w/core/modules/views/templates/views-mini-pager.html.twig index 5fd95dc..ae84fa7 100644 --- c/core/modules/views/templates/views-mini-pager.html.twig +++ w/core/modules/views/templates/views-mini-pager.html.twig @@ -12,6 +12,5 @@ */ #} {% if items %} -