diff --git a/core/includes/ajax.inc b/core/includes/ajax.inc index 837d0f9..c07d44a 100644 --- a/core/includes/ajax.inc +++ b/core/includes/ajax.inc @@ -5,6 +5,8 @@ * Functions for use with Drupal's Ajax framework. */ +use Drupal\Component\Utility\Json; + /** * @defgroup ajax Ajax framework * @{ @@ -217,7 +219,8 @@ * @code * $commands = array(); * $commands[] = ajax_command_replace(NULL, $output); - * $commands[] = ajax_command_prepend(NULL, theme('status_messages')); + * $status_messages = array('#theme' => 'status_messages'); + * $commands[] = ajax_command_prepend(NULL, drupal_render($status_messages)); * return array('#type' => 'ajax', '#commands' => $commands); * @endcode * @@ -300,7 +303,7 @@ function ajax_render($commands = array()) { // Allow modules to alter any Ajax response. drupal_alter('ajax_render', $commands); - return drupal_json_encode($commands); + return Json::encode($commands); } /** diff --git a/core/includes/batch.inc b/core/includes/batch.inc index 15f82f2..d78248d 100644 --- a/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -411,7 +411,7 @@ function _batch_finished() { if (is_callable($batch_set['finished'])) { $queue = _batch_queue($batch_set); $operations = $queue->getAllItems(); - $batch_set['finished']($batch_set['success'], $batch_set['results'], $operations, format_interval($batch_set['elapsed'] / 1000)); + call_user_func_array($batch_set['finished'], array($batch_set['success'], $batch_set['results'], $operations, format_interval($batch_set['elapsed'] / 1000))); } } } diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index fd24e01..e62c07d 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -491,7 +491,7 @@ function drupal_valid_http_host($host) { */ function drupal_settings_initialize() { // Export these settings.php variables to the global namespace. - global $base_url, $databases, $cookie_domain, $drupal_hash_salt, $config_directories, $config; + global $base_url, $databases, $cookie_domain, $config_directories, $config; $settings = array(); $config = array(); @@ -827,7 +827,9 @@ function drupal_page_is_cacheable($allow_caching = NULL) { * @param $append * Whether to append the value to an existing header or to replace it. * - * @deprecated Header handling is being shifted to a Symfony response object. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Symfony\Component\HttpFoundation\Response->headers->set(). + * See https://drupal.org/node/2181523. */ function drupal_add_http_header($name, $value, $append = FALSE) { // The headers as name/value pairs. @@ -860,7 +862,9 @@ function drupal_add_http_header($name, $value, $append = FALSE) { * A string containing the header value, or FALSE if the header has been set, * or NULL if the header has not been set. * - * @deprecated Header handling is being shifted to a Symfony response object. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Symfony\Component\HttpFoundation\Response->headers->get(). + * See https://drupal.org/node/2181523. */ function drupal_get_http_header($name = NULL) { $headers = &drupal_static('drupal_http_headers', array()); @@ -879,7 +883,8 @@ function drupal_get_http_header($name = NULL) { * Header names are case-insensitive, but for maximum compatibility they should * follow "common form" (see RFC 2616, section 4.2). * - * @deprecated Header handling is being shifted to a Symfony response object. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * See https://drupal.org/node/2181523. */ function _drupal_set_preferred_header_name($name = NULL) { static $header_names = array(); @@ -902,7 +907,8 @@ function _drupal_set_preferred_header_name($name = NULL) { * (optional) If TRUE and headers have already been sent, send only the * specified headers. * - * @deprecated Header handling is being shifted to a Symfony response object. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * See https://drupal.org/node/2181523. */ function drupal_send_headers($default_headers = array(), $only_default = FALSE) { $headers_sent = &drupal_static(__FUNCTION__, FALSE); @@ -958,7 +964,8 @@ function drupal_send_headers($default_headers = array(), $only_default = FALSE) * * @see drupal_page_set_cache() * - * @deprecated Header handling is being shifted to a Symfony response object. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * See https://drupal.org/node/2181523. */ function drupal_page_header() { $headers_sent = &drupal_static(__FUNCTION__, FALSE); @@ -1148,12 +1155,11 @@ function format_string($string, array $args = array()) { /** * Encodes special characters in a plain-text string for display as HTML. * - * @see \Drupal\Component\Utility\String::checkPlain() * @see drupal_validate_utf8() * @ingroup sanitization * - * @deprecated as of Drupal 8.0. Use - * Drupal\Component\Utility\String::checkPlain() directly instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\String::checkPlain(). */ function check_plain($text) { return String::checkPlain($text); @@ -1300,7 +1306,7 @@ function watchdog($type, $message, array $variables = NULL, $severity = WATCHDOG // It is possible that the error handling will itself trigger an error. In that case, we could // end up in an infinite loop. To avoid that, we implement a simple static semaphore. - if (!$in_error_state && function_exists('module_implements')) { + if (!$in_error_state && \Drupal::hasService('module_handler')) { $in_error_state = TRUE; // The user object may not exist in all conditions, so 0 is substituted if needed. @@ -1662,10 +1668,13 @@ function drupal_get_user_timezone() { * A salt based on information in settings.php, not in the database. */ function drupal_get_hash_salt() { - global $drupal_hash_salt, $databases; - // If the $drupal_hash_salt variable is empty, a hash of the serialized - // database credentials is used as a fallback salt. - return empty($drupal_hash_salt) ? hash('sha256', serialize($databases)) : $drupal_hash_salt; + $hash_salt = settings()->get('hash_salt'); + // This should never happen, as it breaks user logins and many other services. + // Therefore, explicitly notify the user (developer) by throwing an exception. + if (empty($hash_salt)) { + throw new \RuntimeException('Missing $settings[\'hash_salt\'] in settings.php.'); + } + return $hash_salt; } /** @@ -1843,8 +1852,8 @@ function drupal_get_bootstrap_phase() { /** * Returns the list of enabled modules. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::moduleHandler()->getModuleList(). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::moduleHandler()->getModuleList(). * * @see \Drupal\Core\Extension\ModuleHandler::getModuleList() */ @@ -1856,8 +1865,8 @@ function module_list() { /** * Determines which modules are implementing a hook. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::moduleHandler()->getImplementations($hook). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::moduleHandler()->getImplementations($hook). * * @see \Drupal\Core\Extension\ModuleHandler::getImplementations() */ @@ -1868,13 +1877,13 @@ function module_implements($hook) { /** * Invokes a hook in a particular module. * - * All arguments are passed by value. Use drupal_alter() if you need to pass - * arguments by reference. + * All arguments are passed by value. Use \Drupal::moduleHandler()->alter() if + * you need to pass arguments by reference. * - * @deprecated as of Drupal 8.0. Use + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. Use * \Drupal::moduleHandler()->invoke($module, $hook, $args = array()). * - * @see drupal_alter() + * @see \Drupal\Core\Extension\ModuleHandler::alter() * @see \Drupal\Core\Extension\ModuleHandler::invoke() */ function module_invoke($module, $hook) { @@ -1890,8 +1899,8 @@ function module_invoke($module, $hook) { * All arguments are passed by value. Use drupal_alter() if you need to pass * arguments by reference. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::moduleHandler()->invokeAll($hook). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::moduleHandler()->invokeAll($hook). * * @see drupal_alter() * @see \Drupal\Core\Extension\ModuleHandler::invokeAll() @@ -1906,8 +1915,8 @@ function module_invoke_all($hook) { /** * Passes alterable variables to specific hook_TYPE_alter() implementations. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::moduleHandler()->alter($hook). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::moduleHandler()->alter($hook). * * @see \Drupal\Core\Extension\ModuleHandler::alter() */ @@ -1918,8 +1927,8 @@ function drupal_alter($type, &$data, &$context1 = NULL, &$context2 = NULL) { /** * Determines whether a given module exists. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::moduleHandler()->moduleExists($module). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::moduleHandler()->moduleExists($module). * * @see \Drupal\Core\Extension\ModuleHandler::moduleExists() */ @@ -1930,8 +1939,8 @@ function module_exists($module) { /** * Determines whether a module implements a hook. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::moduleHandler()->implementsHook($module, $hook). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::moduleHandler()->implementsHook($module, $hook). * * @see \Drupal\Core\Extension\ModuleHandler::implementsHook() */ @@ -2070,8 +2079,8 @@ function drupal_language_initialize() { * @param string $type * The type of language object needed, e.g. Language::TYPE_INTERFACE. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::languageManager()->getCurrentLanguage(). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::languageManager()->getCurrentLanguage(). */ function language($type) { return \Drupal::languageManager()->getCurrentLanguage($type); @@ -2089,8 +2098,8 @@ function language($type) { * An associative array of languages, keyed by the language code, ordered by * weight ascending and name ascending. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::languageManager()->getLanguages() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::languageManager()->getLanguages(). */ function language_list($flags = Language::STATE_CONFIGURABLE) { return \Drupal::languageManager()->getLanguages($flags); @@ -2107,8 +2116,8 @@ function language_list($flags = Language::STATE_CONFIGURABLE) { * * @see \Drupal\Core\Language\LanguageManager::getLanguage() * - * @deprecated as of Drupal 8.0. Use \Drupal::languageManager()->getLanguage() - * instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::languageManager()->getLanguage(). */ function language_load($langcode) { return \Drupal::languageManager()->getLanguage($langcode); @@ -2120,8 +2129,10 @@ function language_load($langcode) { * @return \Drupal\Core\Language\Language * A language object. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::languageManager()->getDefaultLanguage() instead. + * @see \Drupal\Core\Language\LanguageManager::getLanguage() + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::languageManager()->getDefaultLanguage(). */ function language_default() { return \Drupal::languageManager()->getDefaultLanguage(); @@ -2621,8 +2632,8 @@ function drupal_check_memory_limit($required, $memory_limit = NULL) { /** * Get locking layer instance. * - * @deprecated Use \Drupal::lock() instead, or even better have the lock service - * injected into your object. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::lock(). * * @return \Drupal\Core\Lock\LockBackendInterface */ diff --git a/core/includes/cache.inc b/core/includes/cache.inc index b39b7ff..771d4d5 100644 --- a/core/includes/cache.inc +++ b/core/includes/cache.inc @@ -24,6 +24,9 @@ * The cache object associated with the specified bin. * * @see \Drupal\Core\Cache\CacheBackendInterface + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::cache(). */ function cache($bin = 'cache') { return \Drupal::cache($bin); @@ -42,7 +45,7 @@ function cache($bin = 'cache') { * @param array $tags * The list of tags to invalidate cache items for. * - * @deprecated 8.x + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. * Use \Drupal\Core\Cache\Cache::invalidateTags(). */ function cache_invalidate_tags(array $tags) { diff --git a/core/includes/common.inc b/core/includes/common.inc index 8fc8c50..43201d8 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -428,7 +428,8 @@ function drupal_get_feeds($delimiter = "\n") { * @return * An array containing query parameters, which can be used for url(). * - * @deprecated as of Drupal 8.0. Use Url::filterQueryParameters() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Url::filterQueryParameters(). */ function drupal_get_query_parameters(array $query = NULL, array $exclude = array(), $parent = '') { if (!isset($query)) { @@ -441,10 +442,10 @@ function drupal_get_query_parameters(array $query = NULL, array $exclude = array * Parses an array into a valid, rawurlencoded query string. * * @see drupal_get_query_parameters() - * @deprecated as of Drupal 8.0. Use Url::buildQuery() instead. * @ingroup php_wrappers * - * @deprecated as of Drupal 8.0. Use Url::buildQuery() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Url::buildQuery(). */ function drupal_http_build_query(array $query, $parent = '') { return Url::buildQuery($query, $parent); @@ -520,7 +521,8 @@ function drupal_get_destination() { * @see url() * @ingroup php_wrappers * - * @deprecated as of Drupal 8.0. Use Url::parse() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Url::parse(). */ function drupal_parse_url($url) { return Url::parse($url); @@ -537,7 +539,8 @@ function drupal_parse_url($url) { * @param $path * The Drupal path to encode. * - * @deprecated as of Drupal 8.0. Use Url::encodePath() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Url::encodePath(). */ function drupal_encode_path($path) { return Url::encodePath($path); @@ -552,7 +555,8 @@ function drupal_encode_path($path) { * @return * TRUE if the URL has the same domain and base path. * - * @deprecated as of Drupal 8.0. Use Url::externalIsLocal() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Url::externalIsLocal(). */ function _external_url_is_local($url) { return Url::externalIsLocal($url, base_path()); @@ -611,7 +615,8 @@ function valid_email_address($mail) { * * @see \Drupal\Component\Utility\Url::isValid() * - * @deprecated as of Drupal 8.0. Use Url::isValid() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Url::isValid(). */ function valid_url($url, $absolute = FALSE) { return Url::isValid($url, $absolute); @@ -633,8 +638,8 @@ function valid_url($url, $absolute = FALSE) { * @return bool * TRUE if no step mismatch has occurred, or FALSE otherwise. * - * @deprecated as of Drupal 8.0. Use - * \Drupal\Component\Utility\Number::validStep() directly instead + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Number::validStep(). */ function valid_number_step($value, $step, $offset = 0.0) { return Number::validStep($value, $step, $offset); @@ -903,8 +908,10 @@ function format_xml_elements($array) { * * @see t() * @see format_string() + * @see \Drupal\Core\StringTranslation\TranslationManager->formatPlural() * - * @deprecated as of Drupal 8.0. Use \Drupal::translation()->formatPlural() + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::translation()->formatPlural(). */ function format_plural($count, $singular, $plural, array $args = array(), array $options = array()) { return \Drupal::translation()->formatPlural($count, $singular, $plural, $args, $options); @@ -986,7 +993,10 @@ function format_size($size, $langcode = NULL) { * @return * A translated string representation of the interval. * - * @deprecated as of Drupal 8.0. Use \Drupal::service('date')->formatInterval(). + * @see \Drupal\Core\Datetime\Date::formatInterval() + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::service('date')->formatInterval(). */ function format_interval($interval, $granularity = 2, $langcode = NULL) { return \Drupal::service('date')->formatInterval($interval, $granularity, $langcode); @@ -1378,7 +1388,7 @@ function base_path() { * Adds a LINK tag with a distinct 'rel' attribute to the page's HEAD. * * This function can be called as long the HTML header hasn't been sent, which - * on normal pages is up through the preprocess step of theme('html'). Adding + * on normal pages is up through the preprocess step of _theme('html'). Adding * a link will overwrite a prior link with the exact same 'rel' and 'href' * attributes. * @@ -2940,8 +2950,15 @@ function drupal_get_library($extension, $name = NULL) { * into a table. The table must have an ID attribute set. If using * theme_table(), the ID may be set as follows: * @code - * $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'my-module-table'))); - * return $output; + * $table = array( + * '#type' => 'table', + * '#header' => $header, + * '#rows' => $rows, + * '#attributes' => array( + * 'id' => 'my-module-table', + * ), + * ); + * return drupal_render($table); * @endcode * * In the theme function for the form, a special class must be added to each @@ -3088,9 +3105,11 @@ function drupal_clear_js_cache() { * We use HTML-safe strings, with several characters escaped. * * @see drupal_json_decode() + * * @ingroup php_wrappers - * @deprecated as of Drupal 8.0. Use Drupal\Component\Utility\Json::encode() - * directly instead. + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Json::encode(). */ function drupal_json_encode($var) { return Json::encode($var); @@ -3100,9 +3119,11 @@ function drupal_json_encode($var) { * Converts an HTML-safe JSON string into its PHP equivalent. * * @see drupal_json_encode() + * * @ingroup php_wrappers - * @deprecated as of Drupal 8.0. Use Drupal\Component\Utility\Json::decode() - * directly instead. + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Json::decode(). */ function drupal_json_decode($var) { return Json::decode($var); @@ -3114,9 +3135,10 @@ function drupal_json_decode($var) { * @return string * The private key. * - * @see \Drupal\Core\Access\CsrfTokenManager + * @see \Drupal\Core\Access\CsrfTokenGenerator * - * @deprecated as of Drupal 8.0. Use the 'private_key' service instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::service('private_key')->get(). */ function drupal_get_private_key() { return \Drupal::service('private_key')->get(); @@ -3139,10 +3161,11 @@ function drupal_get_private_key() { * 'drupal_private_key' configuration variable. * * @see drupal_get_hash_salt() - * @see \Drupal\Core\Access\CsrfTokenManager + * @see \Drupal\Core\Access\CsrfTokenGenerator * @see drupal_session_start() * - * @deprecated as of Drupal 8.0. Use the csrf_token service instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::csrfToken()->get(). */ function drupal_get_token($value = '') { return \Drupal::csrfToken()->get($value); @@ -3162,9 +3185,10 @@ function drupal_get_token($value = '') { * True for a valid token, false for an invalid token. When $skip_anonymous * is true, the return value will always be true for anonymous users. * - * @see \Drupal\Core\Access\CsrfTokenManager + * @see \Drupal\Core\Access\CsrfTokenGenerator * - * @deprecated as of Drupal 8.0. Use the csrf_token service instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use return \Drupal::csrfToken()->validate(). */ function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) { return \Drupal::csrfToken()->validate($token, $value, $skip_anonymous); @@ -3291,7 +3315,7 @@ function drupal_page_set_cache(Response $response, Request $request) { if ($page_compressed) { $cache->data['body'] = gzencode($cache->data['body'], 9, FORCE_GZIP); } - cache('page')->set($cache->cid, $cache->data, $cache->expire, $cache->tags); + \Drupal::cache('page')->set($cache->cid, $cache->data, $cache->expire, $cache->tags); } return $cache; } @@ -3683,6 +3707,20 @@ function drupal_prepare_page($page) { // 'sidebar_first', 'footer', etc. drupal_alter('page', $page); + // The "main" and "secondary" menus are never part of the page-level render + // array and therefore their cache tags will never bubble up into the page + // cache, even though they should be. This happens because they're rendered + // directly by the theme system. + // @todo Remove this once https://drupal.org/node/1869476 lands. + if (theme_get_setting('features.main_menu') && count(menu_main_menu())) { + $main_links_source = _menu_get_links_source('main_links', 'main'); + $page['page_top']['#cache']['tags']['menu'][$main_links_source] = $main_links_source; + } + if (theme_get_setting('features.secondary_menu') && count(menu_secondary_menu())) { + $secondary_links_source = _menu_get_links_source('secondary_links', 'account'); + $page['page_top']['#cache']['tags']['menu'][$secondary_links_source] = $secondary_links_source; + } + // If no module has taken care of the main content, add it to the page now. // This allows the site to still be usable even if no modules that // control page regions (for example, the Block module) are enabled. @@ -3772,9 +3810,9 @@ function drupal_render_page($page) { * $elements['#sorted'] = TRUE to avoid sorting them a second time. * - The main render phase to produce #children for this element takes place: * - If this element has #theme defined and #theme is an implemented theme - * hook/suggestion then theme() is called and must render both the element - * and its children. If #render_children is set, theme() will not be - * called. #render_children is usually only set internally by theme() so + * hook/suggestion then _theme() is called and must render both the element + * and its children. If #render_children is set, _theme() will not be + * called. #render_children is usually only set internally by _theme() so * that we can avoid the situation where drupal_render() called from * within a theme preprocess function creates an infinite loop. * - If this element does not have a defined #theme, or the defined #theme @@ -3792,7 +3830,7 @@ function drupal_render_page($page) { * drupal_process_attached(). * - If this element has an array of #theme_wrappers defined and * #render_children is not set, #children is then re-rendered by passing the - * element in its current state to theme() successively for each item in + * element in its current state to _theme() successively for each item in * #theme_wrappers. Since #theme and #theme_wrappers hooks often define * variables with the same names it is possible to explicitly override each * attribute passed to each #theme_wrappers hook by setting the hook name as @@ -3852,7 +3890,7 @@ function drupal_render_page($page) { * The rendered HTML. * * @see element_info() - * @see theme() + * @see _theme() * @see drupal_process_states() * @see drupal_process_attached() */ @@ -3925,11 +3963,11 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) { // property is set, do not call the #theme function to prevent infinite // recursion. if ($theme_is_implemented && !isset($elements['#render_children'])) { - $elements['#children'] = theme($elements['#theme'], $elements); + $elements['#children'] = _theme($elements['#theme'], $elements); - // If theme() returns FALSE this means that the hook in #theme was not found - // in the registry and so we need to update our flag accordingly. This is - // common for theme suggestions. + // If _theme() returns FALSE this means that the hook in #theme was not + // found in the registry and so we need to update our flag accordingly. This + // is common for theme suggestions. $theme_is_implemented = ($elements['#children'] !== FALSE); } @@ -3972,7 +4010,7 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) { // If the value of a #theme_wrappers item is an array then the theme hook // is found in the key of the item and the value contains attribute // overrides. Attribute overrides replace key/value pairs in $elements for - // only this theme() call. This allows #theme hooks and #theme_wrappers + // only this _theme() call. This allows #theme hooks and #theme_wrappers // hooks to share variable names without conflict or ambiguity. $wrapper_elements = $elements; if (is_string($key)) { @@ -3985,7 +4023,7 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) { $wrapper_hook = $value; } - $elements['#children'] = theme($wrapper_hook, $wrapper_elements); + $elements['#children'] = _theme($wrapper_hook, $wrapper_elements); } } @@ -4171,7 +4209,7 @@ function drupal_render_cache_get(array $elements) { } $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache'; - if (!empty($cid) && $cache = cache($bin)->get($cid)) { + if (!empty($cid) && $cache = \Drupal::cache($bin)->get($cid)) { $cached_element = $cache->data; // Add additional libraries, JavaScript, CSS and other data attached // to this element. @@ -4225,7 +4263,7 @@ function drupal_render_cache_set(&$markup, array $elements) { $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache'; $expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : Cache::PERMANENT; $tags = drupal_render_collect_cache_tags($elements); - cache($bin)->set($cid, $data, $expire, $tags); + \Drupal::cache($bin)->set($cid, $data, $expire, $tags); } /** @@ -4513,7 +4551,7 @@ function drupal_cache_tags_page_get(Response $response) { * added to this string and is also part of the cache key in * drupal_render_cache_set() and drupal_render_cache_get(). * @param $expire - * The cache expire time, passed eventually to cache()->set(). + * The cache expire time, passed eventually to \Drupal::cache()->set(). * @param $granularity * One or more granularity constants passed to drupal_render_cid_parts(). * @@ -4625,9 +4663,8 @@ function drupal_render_cid_create($elements) { * @return int * The comparison result for uasort(). * - * @see \Drupal\Component\Utility\SortArray::sortByWeightProperty() - * - * @deprecated as of Drupal 8.0. Use SortArray::sortByWeightProperty() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\SortArray::sortByWeightProperty(). */ function element_sort($a, $b) { return SortArray::sortByWeightProperty($a, $b); @@ -4649,9 +4686,8 @@ function element_sort($a, $b) { * @return int * The comparison result for uasort(). * - * @see \Drupal\Component\Utility\SortArray::sortByTitleProperty() - * - * @deprecated as of Drupal 8.0. Use SortArray::sortByTitleProperty() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\SortArray::sortByTitleProperty(). */ function element_sort_by_title($a, $b) { return SortArray::sortByTitleProperty($a, $b); @@ -4712,9 +4748,8 @@ function element_info_property($type, $property_name, $default = NULL) { * @return int * The comparison result for uasort(). * - * @see \Drupal\Component\Utility\SortArray::sortByTitleElement() - * - * @deprecated as of Drupal 8.0. Use SortArray::sortByTitleElement() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\SortArray::sortByTitleElement(). */ function drupal_sort_title($a, $b) { return SortArray::sortByTitleElement($a, $b); @@ -4723,9 +4758,8 @@ function drupal_sort_title($a, $b) { /** * Checks if the key is a property. * - * @see \Drupal\Core\Render\Element::property() - * - * @deprecated as of Drupal 8.0. Use Element::property() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Core\Render\Element::property(). */ function element_property($key) { return Element::property($key); @@ -4734,9 +4768,8 @@ function element_property($key) { /** * Gets properties of a structured array element (keys beginning with '#'). * - * @see \Drupal\Core\Render\Element::properties() - * - * @deprecated as of Drupal 8.0. Use Element::properties() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Core\Render\Element::properties(). */ function element_properties($element) { return Element::properties($element); @@ -4745,9 +4778,8 @@ function element_properties($element) { /** * Checks if the key is a child. * - * @see \Drupal\Core\Render\Element::child() - * - * @deprecated as of Drupal 8.0. Use Element::child() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Core\Render\Element::child(). */ function element_child($key) { return Element::child($key); @@ -4767,9 +4799,8 @@ function element_child($key) { * @return * The array keys of the element's children. * - * @see \Drupal\Core\Render\Element::children() - * - * @deprecated as of Drupal 8.0. Use Element::children() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Core\Render\Element::children(). */ function element_children(&$elements, $sort = FALSE) { return Element::children($elements, $sort); @@ -4784,9 +4815,8 @@ function element_children(&$elements, $sort = FALSE) { * @return * The array keys of the element's visible children. * - * @see \Drupal\Core\Render\Element::getVisibleChildren() - * - * @deprecated as of Drupal 8.0. Use Element::getVisibleChildren() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Core\Render\Element::getVisibleChildren(). */ function element_get_visible_children(array $elements) { return Element::getVisibleChildren($elements); @@ -4804,9 +4834,8 @@ function element_get_visible_children(array $elements) { * except for the leading '#', then an attribute name value is sufficient and * no property name needs to be specified. * - * @see \Drupal\Core\Render\Element::setAttributes() - * - * @deprecated as of Drupal 8.0. Use Element::setAttributes() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Core\Render\Element::setAttributes(). */ function element_set_attributes(array &$element, array $map) { Element::setAttributes($element, $map); @@ -4823,8 +4852,8 @@ function element_set_attributes(array &$element, array $map) { * * @see \Drupal\Core\Extension\InfoParser::parse(). * - * @deprecated as of Drupal 8.0. Use \Drupal::service('info_parser')->parse() - * instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::service('info_parser')->parse(). */ function drupal_parse_info_file($filename) { return \Drupal::service('info_parser')->parse($filename); @@ -4858,9 +4887,9 @@ function watchdog_severity_levels() { * Explodes a string of tags into an array. * * @see drupal_implode_tags() - * @see \Drupal\Component\Utility\String::explodeTags(). * - * @deprecated as of Drupal 8.0. Use Tags::explode() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Tags::explode(). */ function drupal_explode_tags($tags) { return Tags::explode($tags); @@ -4870,9 +4899,9 @@ function drupal_explode_tags($tags) { * Implodes an array of tags into a string. * * @see drupal_explode_tags() - * @see \Drupal\Component\Utility\String::implodeTags(). * - * @deprecated as of Drupal 8.0. Use Tags::implode() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Tags::implode(). */ function drupal_implode_tags($tags) { return Tags::implode($tags); diff --git a/core/includes/config.inc b/core/includes/config.inc index 9604ee5..c673744 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -22,13 +22,13 @@ function config_get_storage_names_with_prefix($prefix = '') { * @code \Drupal::config('book.admin') @endcode will return a configuration * object in which the book module can store its administrative settings. * - * @deprecated Deprecated since Drupal 8.x-dev, to be removed in Drupal 8.0. - * Use \Drupal::config() instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::config(). * * @param string $name * The name of the configuration object to retrieve. The name corresponds to - * a configuration file. For @code \Drupal::config('book.admin') @endcode, the - * config object returned will contain the contents of book.admin + * a configuration file. For @code \Drupal::config('book.admin') @endcode, + * the config object returned will contain the contents of book.admin * configuration file. * * @return \Drupal\Core\Config\Config diff --git a/core/includes/entity.inc b/core/includes/entity.inc index c2054c2..9e93990 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -11,33 +11,6 @@ use Drupal\Core\Language\Language; /** - * Gets the entity definition for an entity type. - * - * @param string|null $entity_type - * (optional) The entity type (e.g. 'node'). Leave NULL to retrieve - * information for all entity types. - * - * @return array - * An array containing the entity type's definition, as retrieved with - * \Drupal\Core\Entity\EntityManagerInterface. If $entity_type is NULL, an - * associative array of all entity type definitions keyed by entity type is - * returned. - * - * @see \Drupal\Core\Entity\EntityManagerInterface - * @see hook_entity_info_alter() - * - * @deprecated Use \Drupal\Core\Entity\EntityManagerInterface::getDefinitions() directly. - */ -function entity_get_info($entity_type = NULL) { - if (empty($entity_type)) { - return \Drupal::entityManager()->getDefinitions(); - } - else { - return \Drupal::entityManager()->getDefinition($entity_type); - } -} - -/** * Resets the cached information about entity types. */ function entity_info_cache_clear() { @@ -121,7 +94,7 @@ function entity_get_form_modes($entity_type = NULL) { $form_modes = &drupal_static(__FUNCTION__); if (!$form_modes) { $langcode = language(Language::TYPE_INTERFACE)->id; - if ($cache = cache()->get("entity_form_mode_info:$langcode")) { + if ($cache = \Drupal::cache()->get("entity_form_mode_info:$langcode")) { $form_modes = $cache->data; } else { @@ -131,7 +104,7 @@ function entity_get_form_modes($entity_type = NULL) { $form_modes[$form_mode_entity_type][$form_mode_name] = (array) $form_mode; } drupal_alter('entity_form_mode_info', $form_modes); - cache()->set("entity_form_mode_info:$langcode", $form_modes, Cache::PERMANENT, array('entity_info' => TRUE)); + \Drupal::cache()->set("entity_form_mode_info:$langcode", $form_modes, Cache::PERMANENT, array('entity_types' => TRUE)); } } @@ -159,7 +132,7 @@ function entity_get_view_modes($entity_type = NULL) { $view_modes = &drupal_static(__FUNCTION__); if (!$view_modes) { $langcode = language(Language::TYPE_INTERFACE)->id; - if ($cache = cache()->get("entity_view_mode_info:$langcode")) { + if ($cache = \Drupal::cache()->get("entity_view_mode_info:$langcode")) { $view_modes = $cache->data; } else { @@ -169,7 +142,7 @@ function entity_get_view_modes($entity_type = NULL) { $view_modes[$view_mode_entity_type][$view_mode_name] = (array) $view_mode; } drupal_alter('entity_view_mode_info', $view_modes); - cache()->set("entity_view_mode_info:$langcode", $view_modes, Cache::PERMANENT, array('entity_info' => TRUE)); + \Drupal::cache()->set("entity_view_mode_info:$langcode", $view_modes, Cache::PERMANENT, array('entity_types' => TRUE)); } } @@ -397,7 +370,10 @@ function entity_create($entity_type, array $values = array()) { * * @return \Drupal\Core\Entity\EntityStorageControllerInterface * - * @deprecated Use \Drupal\Core\Entity\EntityManagerInterface::getStorageController(). + * @see \Drupal\Core\Entity\EntityManagerInterface::getStorageController(). + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::entityManager()->getStorageController(). */ function entity_get_controller($entity_type) { return \Drupal::entityManager() @@ -435,7 +411,10 @@ function entity_page_label(EntityInterface $entity, $langcode = NULL) { * @return \Drupal\Core\Entity\EntityAccessControllerInterface * An entity access controller instance. * - * @deprecated Use \Drupal\Core\Entity\EntityManagerInterface::getAccessController(). + * @see \Drupal\Core\Entity\EntityManagerInterface::getAccessController(). + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::entityManager()->getAccessController(). */ function entity_access_controller($entity_type) { return \Drupal::entityManager() @@ -451,7 +430,10 @@ function entity_access_controller($entity_type) { * @return \Drupal\Core\Entity\EntityListControllerInterface * An entity list controller. * - * @deprecated Use \Drupal\Core\Entity\EntityManagerInterface::getFormController(). + * @see \Drupal\Core\Entity\EntityManagerInterface::getListController(). + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::entityManager()->getListController(). */ function entity_list_controller($entity_type) { return \Drupal::entityManager() diff --git a/core/includes/errors.inc b/core/includes/errors.inc index 208a679..761b7bd 100644 --- a/core/includes/errors.inc +++ b/core/includes/errors.inc @@ -169,7 +169,7 @@ function _drupal_log_error($error, $fatal = FALSE) { } } - if (\Drupal::request()->isXmlHttpRequest()) { + if (\Drupal::hasRequest() && \Drupal::request()->isXmlHttpRequest()) { if ($fatal) { if (error_displayable($error)) { // When called from JavaScript, simply output the error message. @@ -289,7 +289,8 @@ function _drupal_get_error_level() { * @return string * A plain-text line-wrapped string ready to be put inside
.
  *
- * @deprecated Use \Drupal\Core\Utility\Error::formatBacktrace() instead.
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal\Core\Utility\Error::formatBacktrace().
  */
 function format_backtrace(array $backtrace) {
   return Error::formatBacktrace($backtrace);
diff --git a/core/includes/form.inc b/core/includes/form.inc
index 450ce84..96eb0d0 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -106,7 +106,10 @@
 /**
  * Returns a renderable form array for a given form ID.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->getForm()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->getForm().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::getForm().
  */
 function drupal_get_form($form_arg) {
   return call_user_func_array(array(\Drupal::formBuilder(), 'getForm'), func_get_args());
@@ -115,7 +118,10 @@ function drupal_get_form($form_arg) {
 /**
  * Builds and processes a form for a given form ID.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->buildForm()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->buildForm().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::buildForm().
  */
 function drupal_build_form($form_id, &$form_state) {
   return \Drupal::formBuilder()->buildForm($form_id, $form_state);
@@ -124,7 +130,10 @@ function drupal_build_form($form_id, &$form_state) {
 /**
  * Retrieves default values for the $form_state array.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->getFormStateDefaults()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->getFormStateDefaults().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::getFormStateDefaults().
  */
 function form_state_defaults() {
   return \Drupal::formBuilder()->getFormStateDefaults();
@@ -133,7 +142,10 @@ function form_state_defaults() {
 /**
  * Constructs a new $form from the information in $form_state.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->rebuildForm()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->rebuildForm().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::rebuildForm().
  */
 function drupal_rebuild_form($form_id, &$form_state, $old_form = NULL) {
   return \Drupal::formBuilder()->rebuildForm($form_id, $form_state, $old_form);
@@ -142,7 +154,10 @@ function drupal_rebuild_form($form_id, &$form_state, $old_form = NULL) {
 /**
  * Fetches a form from the cache.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->getCache()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->getCache().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::getCache().
  */
 function form_get_cache($form_build_id, &$form_state) {
   return \Drupal::formBuilder()->getCache($form_build_id, $form_state);
@@ -151,7 +166,10 @@ function form_get_cache($form_build_id, &$form_state) {
 /**
  * Stores a form in the cache.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->setCache()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->setCache().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::setCache().
  */
 function form_set_cache($form_build_id, $form, $form_state) {
   \Drupal::formBuilder()->setCache($form_build_id, $form, $form_state);
@@ -209,7 +227,10 @@ function form_load_include(&$form_state, $type, $module, $name = NULL) {
 /**
  * Retrieves, populates, and processes a form.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->submitForm()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->submitForm().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::submitForm().
  */
 function drupal_form_submit($form_arg, &$form_state) {
   \Drupal::formBuilder()->submitForm($form_arg, $form_state);
@@ -218,7 +239,10 @@ function drupal_form_submit($form_arg, &$form_state) {
 /**
  * Retrieves the structured array that defines a given form.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->retrieveForm()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->retrieveForm().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::retrieveForm().
  */
 function drupal_retrieve_form($form_id, &$form_state) {
   return \Drupal::formBuilder()->retrieveForm($form_id, $form_state);
@@ -227,7 +251,10 @@ function drupal_retrieve_form($form_id, &$form_state) {
 /**
  * Processes a form submission.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->processForm()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->processForm().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::processForm().
  */
 function drupal_process_form($form_id, &$form, &$form_state) {
   \Drupal::formBuilder()->processForm($form_id, $form, $form_state);
@@ -236,7 +263,10 @@ function drupal_process_form($form_id, &$form, &$form_state) {
 /**
  * Prepares a structured form array.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->prepareForm()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->prepareForm().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::prepareForm().
  */
 function drupal_prepare_form($form_id, &$form, &$form_state) {
   \Drupal::formBuilder()->prepareForm($form_id, $form, $form_state);
@@ -245,7 +275,10 @@ function drupal_prepare_form($form_id, &$form, &$form_state) {
 /**
  * Validates user-submitted form data in the $form_state array.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->validateForm()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->validateForm().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::validateForm().
  */
 function drupal_validate_form($form_id, &$form, &$form_state) {
   \Drupal::formBuilder()->validateForm($form_id, $form, $form_state);
@@ -254,7 +287,10 @@ function drupal_validate_form($form_id, &$form, &$form_state) {
 /**
  * Redirects the user to a URL after a form has been processed.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->redirectForm()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->redirectForm().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::redirectForm().
  */
 function drupal_redirect_form($form_state) {
   return \Drupal::formBuilder()->redirectForm($form_state);
@@ -263,7 +299,10 @@ function drupal_redirect_form($form_state) {
 /**
  * Executes custom validation and submission handlers for a given form.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->executeHandlers()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->executeHandlers().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::executeHandlers().
  */
 function form_execute_handlers($type, &$form, &$form_state) {
   \Drupal::formBuilder()->executeHandlers($type, $form, $form_state);
@@ -272,7 +311,10 @@ function form_execute_handlers($type, &$form, &$form_state) {
 /**
  * Files an error against a form element.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->setErrorByName()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->setErrorByName().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::setErrorByName().
  */
 function form_set_error($name, array &$form_state, $message = '') {
   \Drupal::formBuilder()->setErrorByName($name, $form_state, $message);
@@ -281,7 +323,10 @@ function form_set_error($name, array &$form_state, $message = '') {
 /**
  * Clears all errors against all form elements made by form_set_error().
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->clearErrors()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->clearErrors().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::clearErrors().
  */
 function form_clear_error(array &$form_state) {
   \Drupal::formBuilder()->clearErrors($form_state);
@@ -290,7 +335,10 @@ function form_clear_error(array &$form_state) {
 /**
  * Returns an associative array of all errors.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->getErrors()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->getErrors().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::getErrors().
  */
 function form_get_errors(array &$form_state) {
   return \Drupal::formBuilder()->getErrors($form_state);
@@ -299,7 +347,10 @@ function form_get_errors(array &$form_state) {
 /**
  * Returns the error message filed against the given form element.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->getError()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->getError().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::getError().
  */
 function form_get_error($element, array &$form_state) {
   return \Drupal::formBuilder()->getError($element, $form_state);
@@ -308,7 +359,10 @@ function form_get_error($element, array &$form_state) {
 /**
  * Flags an element as having an error.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->setError()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->setError().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::setError().
  */
 function form_error(&$element, array &$form_state, $message = '') {
   \Drupal::formBuilder()->setError($element, $form_state, $message);
@@ -317,7 +371,10 @@ function form_error(&$element, array &$form_state, $message = '') {
 /**
  * Builds and processes all elements in the structured form array.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->doBuildForm()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->doBuildForm().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::doBuildForm().
  */
 function form_builder($form_id, &$element, &$form_state) {
   return \Drupal::formBuilder()->doBuildForm($form_id, $element, $form_state);
@@ -718,7 +775,10 @@ function form_type_token_value($element, $input = FALSE) {
 /**
  * Changes submitted form values during form validation.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->setValue()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->setValue().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::setValue().
  */
 function form_set_value($element, $value, &$form_state) {
   \Drupal::formBuilder()->setValue($element, $value, $form_state);
@@ -737,7 +797,10 @@ function form_set_value($element, $value, &$form_state) {
  * @return
  *   An array with all hierarchical elements flattened to a single array.
  *
- * @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->flattenOptions()
+ * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
+ *   Use \Drupal::formBuilder()->flattenOptions().
+ *
+ * @see \Drupal\Core\Form\FormBuilderInterface::flattenOptions().
  */
 function form_options_flatten($array) {
   return \Drupal::formBuilder()->flattenOptions($array);
@@ -951,30 +1014,49 @@ function theme_fieldset($variables) {
   element_set_attributes($element, array('id'));
   _form_set_attributes($element, array('form-wrapper'));
 
+  $element['#attributes']['class'][] = 'form-item';
+
   if (!empty($element['#description'])) {
     $description_id = $element['#attributes']['id'] . '--description';
     $element['#attributes']['aria-describedby'] = $description_id;
   }
 
+  // If the element is required, a required marker is appended to the label.
+  // @see theme_form_element_label()
+  $required = '';
+  if (!empty($element['#required'])) {
+    $marker = array(
+      '#theme' => 'form_required_marker',
+      '#element' => $element,
+    );
+    $required = drupal_render($marker);
+  }
+
   $legend_attributes = array();
   if (isset($element['#title_display']) && $element['#title_display'] == 'invisible') {
     $legend_attributes['class'][] = 'visually-hidden';
   }
 
   $output = '';
-  if (!empty($element['#title'])) {
+
+  if ((isset($element['#title']) && $element['#title'] !== '') || !empty($element['#required'])) {
     // Always wrap fieldset legends in a SPAN for CSS positioning.
-    $output .= '' . $element['#title'] . '';
+    $output .= '';
+    $output .= t('!title!required', array('!title' => $element['#title'], '!required' => $required));
+    $output .= '';
   }
   $output .= '
'; - if (!empty($element['#description'])) { - $attributes = array('class' => 'fieldset-description', 'id' => $description_id); - $output .= '' . $element['#description'] . '
'; + if (isset($element['#field_prefix'])) { + $output .= '' . $element['#field_prefix'] . ' '; } $output .= $element['#children']; - if (isset($element['#value'])) { - $output .= $element['#value']; + if (isset($element['#field_suffix'])) { + $output .= ' ' . $element['#field_suffix'] . ''; + } + if (!empty($element['#description'])) { + $attributes = array('class' => 'description', 'id' => $description_id); + $output .= '' . $element['#description'] . ''; } $output .= ''; $output .= "\n"; @@ -990,7 +1072,7 @@ function theme_fieldset($variables) { * An associative array containing: * - element: An associative array containing the properties of the element. * Properties used: #attributes, #children, #collapsed, #collapsible, - * #description, #id, #title, #value. + * #description, #id, #title, #value, #optional. * * @ingroup themeable */ @@ -1259,7 +1341,10 @@ function form_pre_render_conditional_form_element($element) { } if (isset($element['#title']) || isset($element['#description'])) { - $element['#theme_wrappers'][] = 'form_element'; + // @see #type 'fieldgroup' + $element['#theme_wrappers'][] = 'fieldset'; + $element['#attributes']['class'][] = 'fieldgroup'; + $element['#attributes']['class'][] = 'form-composite'; } return $element; } @@ -1956,9 +2041,6 @@ function form_process_group(&$element, &$form_state) { $form_state['groups'][$group][] = &$element; } - // Contains form element summary functionalities. - $element['#attached']['library'][] = array('core', 'drupal.form'); - return $element; } @@ -1985,6 +2067,14 @@ function form_pre_render_details($element) { $element['#attributes']['open'] = 'open'; } + // Do not render optional details elements if there are no children. + if (isset($element['#parents'])) { + $group = implode('][', $element['#parents']); + if (!empty($element['#optional']) && !element_get_visible_children($element['#groups'][$group])) { + $element['#printed'] = TRUE; + } + } + return $element; } @@ -2025,6 +2115,9 @@ function form_pre_render_group($element) { } if (isset($element['#group'])) { + // Contains form element summary functionalities. + $element['#attached']['library'][] = array('core', 'drupal.form'); + $group = $element['#group']; // If this element belongs to a group, but the group-holding element does // not exist, we need to render it (at its original location). diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 5b2b7b6..872b55c 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1255,17 +1255,14 @@ function install_settings_form_submit($form, &$form_state) { 'value' => $database, 'required' => TRUE, ); - $settings['drupal_hash_salt'] = (object) array( + $settings['settings']['hash_salt'] = (object) array( 'value' => Crypt::randomStringHashed(55), 'required' => TRUE, ); - // Remember the profile which was used. - $settings['settings'] = array( - 'install_profile' => (object) array( - 'value' => $install_state['parameters']['profile'], - 'required' => TRUE, - ), + $settings['settings']['install_profile'] = (object) array( + 'value' => $install_state['parameters']['profile'], + 'required' => TRUE, ); drupal_rewrite_settings($settings); diff --git a/core/includes/install.inc b/core/includes/install.inc index 895f068..d7a7573 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -7,6 +7,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Drupal\Component\Utility\Crypt; +use Drupal\Component\Utility\Settings; use Drupal\Core\Database\Database; use Drupal\Core\DrupalKernel; @@ -199,8 +200,14 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { } // Build list of setting names and insert the values into the global namespace. $variable_names = array(); + $settings_settings = array(); foreach ($settings as $setting => $data) { - _drupal_rewrite_settings_global($GLOBALS[$setting], $data); + if ($setting != 'settings') { + _drupal_rewrite_settings_global($GLOBALS[$setting], $data); + } + else { + _drupal_rewrite_settings_global($settings_settings, $data); + } $variable_names['$'. $setting] = $setting; } $contents = file_get_contents(DRUPAL_ROOT . '/' . $settings_file); @@ -307,6 +314,14 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { if (file_put_contents(DRUPAL_ROOT . '/' . $settings_file, $buffer) === FALSE) { throw new Exception(t('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file))); } + else { + // In case any $settings variables were written, import them into the + // Settings singleton. + if (!empty($settings_settings)) { + $old_settings = settings()->getAll(); + new Settings($settings_settings + $old_settings); + } + } } else { throw new Exception(t('Failed to open %settings. Verify the file permissions.', array('%settings' => $settings_file))); @@ -648,8 +663,9 @@ function drupal_install_system($install_state) { ->set('enabled.system', 0) ->save(); - // Update the module list to include it. + // Update the module list to include it. Reboot the kernel too. \Drupal::moduleHandler()->setModuleList(array('system' => $system_path . '/system.module')); + $kernel->updateModules(array('system' => $system_path . '/system.module')); \Drupal::service('config.installer')->installDefaultConfig('module', 'system'); @@ -660,7 +676,7 @@ function drupal_install_system($install_state) { ->save(); } - module_invoke('system', 'install'); + \Drupal::moduleHandler()->invoke('system', 'install'); } /** @@ -1012,7 +1028,7 @@ function drupal_requirements_severity(&$requirements) { function drupal_check_module($module) { module_load_install($module); // Check requirements - $requirements = module_invoke($module, 'requirements', 'install'); + $requirements = \Drupal::moduleHandler()->invoke($module, 'requirements', array('install')); if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) { // Print any error messages foreach ($requirements as $requirement) { diff --git a/core/includes/mail.inc b/core/includes/mail.inc index 61dfb7e..0209bd5 100644 --- a/core/includes/mail.inc +++ b/core/includes/mail.inc @@ -5,6 +5,9 @@ * API functions for processing and sending e-mail. */ +use Drupal\Component\Utility\Html; +use Drupal\Component\Utility\Xss; + /** * Composes and optionally sends an e-mail message. * @@ -151,8 +154,9 @@ function drupal_mail($module, $key, $to, $langcode, $params = array(), $reply = $message['headers'] = $headers; // Build the e-mail (get subject and body, allow additional headers) by - // invoking hook_mail() on this module. We cannot use module_invoke() as - // we need to have $message by reference in hook_mail(). + // invoking hook_mail() on this module. We cannot use + // moduleHandler()->invoke() as we need to have $message by reference in + // hook_mail(). if (function_exists($function = $module . '_mail')) { $function($key, $message, $params); } @@ -287,7 +291,7 @@ function drupal_html_to_text($string, $allowed_tags = NULL) { $allowed_tags = isset($allowed_tags) ? array_intersect($supported_tags, $allowed_tags) : $supported_tags; // Make sure tags, entities and attributes are well-formed and properly nested. - $string = _filter_htmlcorrector(filter_xss($string, $allowed_tags)); + $string = Html::normalize(Xss::filter($string, $allowed_tags)); // Apply inline styles. $string = preg_replace('! +)[^>]*)?>!i', '/', $string); diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 8619448..c491641 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -1047,6 +1047,9 @@ function menu_tree_output($tree) { // Add the theme wrapper for outer markup. // Allow menu-specific theme overrides. $build['#theme_wrappers'][] = 'menu_tree__' . strtr($data['link']['menu_name'], '-', '_'); + // Set cache tag. + $menu_name = $data['link']['menu_name']; + $build['#cache']['tags']['menu'][$menu_name] = $menu_name; } return $build; @@ -1083,7 +1086,7 @@ function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) { if (!isset($tree[$cid])) { // If the static variable doesn't have the data, check {cache_menu}. - $cache = cache('menu')->get($cid); + $cache = \Drupal::cache('menu')->get($cid); if ($cache && isset($cache->data)) { // If the cache entry exists, it contains the parameters for // menu_build_tree(). @@ -1110,7 +1113,7 @@ function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) { } // Cache the tree building parameters using the page-specific cid. - cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name)); + \Drupal::cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name)); } // Build the tree using the parameters; the resulting tree will be cached @@ -1228,7 +1231,7 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail = if (!isset($tree[$cid])) { // If the static variable doesn't have the data, check {cache_menu}. - $cache = cache('menu')->get($cid); + $cache = \Drupal::cache('menu')->get($cid); if ($cache && isset($cache->data)) { // If the cache entry exists, it contains the parameters for // menu_build_tree(). @@ -1296,7 +1299,7 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail = $tree_parameters['active_trail'] = $active_trail; } // Cache the tree building parameters using the page-specific cid. - cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name)); + \Drupal::cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name)); } // Build the tree using the parameters; the resulting tree will be cached @@ -1364,7 +1367,7 @@ function _menu_build_tree($menu_name, array $parameters = array()) { // If we do not have this tree in the static cache, check {cache_menu}. if (!isset($trees[$tree_cid])) { - $cache = cache('menu')->get($tree_cid); + $cache = \Drupal::cache('menu')->get($tree_cid); if ($cache && isset($cache->data)) { $trees[$tree_cid] = $cache->data; } @@ -1407,7 +1410,7 @@ function _menu_build_tree($menu_name, array $parameters = array()) { menu_tree_collect_node_links($data['tree'], $data['node_links']); // Cache the data, if it is not already in the cache. - cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name)); + \Drupal::cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name)); $trees[$tree_cid] = $data; } @@ -1705,10 +1708,7 @@ function menu_list_system_menus() { * Returns an array of links to be rendered as the Main menu. */ function menu_main_menu() { - $config = \Drupal::config('menu.settings'); - $menu_enabled = \Drupal::moduleHandler()->moduleExists('menu'); - // When menu module is not enabled, we need a hardcoded default value. - $main_links_source = $menu_enabled ? $config->get('main_links') : 'main'; + $main_links_source = _menu_get_links_source('main_links', 'main'); return menu_navigation_links($main_links_source); } @@ -1716,11 +1716,8 @@ function menu_main_menu() { * Returns an array of links to be rendered as the Secondary links. */ function menu_secondary_menu() { - $config = \Drupal::config('menu.settings'); - $menu_enabled = \Drupal::moduleHandler()->moduleExists('menu'); - // When menu module is not enabled, we need a hardcoded default value. - $main_links_source = $menu_enabled ? $config->get('main_links') : 'main'; - $secondary_links_source = $menu_enabled ? $config->get('secondary_links') : 'account'; + $main_links_source = _menu_get_links_source('main_links', 'main'); + $secondary_links_source = _menu_get_links_source('secondary_links', 'account'); // If the secondary menu source is set as the primary menu, we display the // second level of the primary menu. @@ -1733,6 +1730,22 @@ function menu_secondary_menu() { } /** + * Returns the source of links of a menu. + * + * @param string $name + * A string configuration key of menu link source. + * @param string $default + * Default menu name. + * + * @return string + * Returns menu name, if exist + */ +function _menu_get_links_source($name, $default) { + $config = \Drupal::config('menu.settings'); + return \Drupal::moduleHandler()->moduleExists('menu') ? $config->get($name) : $default; +} + +/** * Returns an array of links for a navigation menu. * * @param $menu_name @@ -2351,22 +2364,13 @@ function menu_get_active_trail() { } /** - * Clears the cached cached data for a single named menu. - */ -function menu_cache_clear($menu_name = 'tools') { - Cache::deleteTags(array('menu' => $menu_name)); - // Also clear the menu system static caches. - menu_reset_static_cache(); -} - -/** * Clears all cached menu data. * * This should be called any time broad changes * might have been made to the router items or menu links. */ function menu_cache_clear_all() { - cache('menu')->deleteAll(); + \Drupal::cache('menu')->deleteAll(); menu_reset_static_cache(); } @@ -2716,13 +2720,13 @@ function _menu_clear_page_cache() { // Clear the page and block caches, but at most twice, including at // the end of the page load when there are multiple links saved or deleted. if ($cache_cleared == 0) { - cache_invalidate_tags(array('content' => TRUE)); + Cache::invalidateTags(array('content' => TRUE)); // Keep track of which menus have expanded items. _menu_set_expanded_menus(); $cache_cleared = 1; } elseif ($cache_cleared == 1) { - drupal_register_shutdown_function('cache_invalidate_tags', array('content' => TRUE)); + drupal_register_shutdown_function('Drupal\Core\Cache\Cache::invalidateTags', array('content' => TRUE)); // Keep track of which menus have expanded items. drupal_register_shutdown_function('_menu_set_expanded_menus'); $cache_cleared = 2; diff --git a/core/includes/module.inc b/core/includes/module.inc index 3d03b8e..4c60604 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -31,7 +31,7 @@ */ function system_list($type) { $lists = &drupal_static(__FUNCTION__); - if ($cached = cache('bootstrap')->get('system_list')) { + if ($cached = \Drupal::cache('bootstrap')->get('system_list')) { $lists = $cached->data; } else { @@ -93,7 +93,7 @@ function system_list($type) { // Set the theme engine prefix. $lists['theme'][$key]->prefix = ($lists['theme'][$key]->info['engine'] == 'theme') ? $base_key : $lists['theme'][$key]->info['engine']; } - cache('bootstrap')->set('system_list', $lists); + \Drupal::cache('bootstrap')->set('system_list', $lists); } // To avoid a separate database lookup for the filepath, prime the // drupal_get_filename() static cache with all enabled modules and themes. @@ -111,8 +111,8 @@ function system_list_reset() { drupal_static_reset('system_list'); drupal_static_reset('system_rebuild_module_data'); drupal_static_reset('list_themes'); - cache('bootstrap')->delete('system_list'); - cache()->delete('system_info'); + \Drupal::cache('bootstrap')->delete('system_list'); + \Drupal::cache()->delete('system_info'); // Clear the library info cache. // Libraries may be provided by all extension types, and may be altered by any @@ -212,8 +212,10 @@ function module_load_include($type, $module, $name = NULL) { /** * Installs a given list of modules. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::moduleHandler()->install($module_list, $enable_dependencies = TRUE) + * @see \Drupal\Core\Extension\ModuleHandlerInterface::install() + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. Use + * \Drupal::moduleHandler()->install($module_list, $enable_dependencies = TRUE). */ function module_install($module_list, $enable_dependencies = TRUE) { return \Drupal::moduleHandler()->install($module_list, $enable_dependencies); @@ -222,8 +224,10 @@ function module_install($module_list, $enable_dependencies = TRUE) { /** * Installs a given list of modules. * - * @deprecated as of Drupal 8.0. Use - * \Drupal::moduleHandler()->install($module_list, $enable_dependencies = TRUE). + * @see \Drupal\Core\Extension\ModuleHandlerInterface::module_install() + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. Use + * \Drupal::moduleHandler()->uninstall($module_list, $enable_dependencies = TRUE). */ function module_uninstall($module_list = array(), $uninstall_dependents = TRUE) { return \Drupal::moduleHandler()->uninstall($module_list, $uninstall_dependents); diff --git a/core/includes/pager.inc b/core/includes/pager.inc index 9874689..f90066c 100644 --- a/core/includes/pager.inc +++ b/core/includes/pager.inc @@ -36,10 +36,10 @@ function pager_find_page($element = 0) { } /** - * Initializes a pager for theme('pager'). + * Initializes a pager for _theme('pager'). * * This function sets up the necessary global variables so that future calls - * to theme('pager') will render a pager that correctly corresponds to the + * to _theme('pager') will render a pager that correctly corresponds to the * items being displayed. * * If the items being displayed result from a database query performed using @@ -67,10 +67,14 @@ function pager_find_page($element = 0) { * // Next, retrieve and display the items for the current page. * $offset = $num_per_page * $page; * $result = mymodule_select("SELECT * FROM data " . $where . " LIMIT %d, %d", $offset, $num_per_page)->fetchAll(); - * $output = theme('mymodule_results', array('result' => $result)); + * $output = drupal_render( + * '#theme' => 'mymodule_results', + * '#result' => $result, + * ); * * // Finally, display the pager controls, and return. - * $output .= theme('pager'); + * $pager = array('#theme' => 'pager'); + * $output .= drupal_render($pager); * return $output; * @endcode * @@ -93,10 +97,16 @@ function pager_find_page($element = 0) { * pager_default_initialize($result->total, $num_per_page); * * // Display the search results. - * $output = theme('search_results', array('results' => $result->data, 'type' => 'remote')); + * $search_results = array( + * '#theme' => 'search_results', + * '#results' => $result->data, + * '#type' => 'remote', + * ); + * $output = drupal_render($search_results); * * // Finally, display the pager controls, and return. - * $output .= theme('pager'); + * $pager = array('#theme' => 'pager'); + * $output .= drupal_render($pager); * return $output; * @endcode * @@ -148,9 +158,9 @@ function pager_get_query_parameters() { * * Default template: pager.html.twig. * - * Menu callbacks that display paged query results should call theme('pager') to - * retrieve a pager control so that users can view other results. Format a list - * of nearby pages with additional query results. + * Menu callbacks that display paged query results should call _theme('pager') + * to retrieve a pager control so that users can view other results. Format a + * list of nearby pages with additional query results. * * @param array $variables * An associative array containing: diff --git a/core/includes/schema.inc b/core/includes/schema.inc index bb1c6e6..c9ee6ae 100644 --- a/core/includes/schema.inc +++ b/core/includes/schema.inc @@ -65,7 +65,7 @@ function drupal_get_complete_schema($rebuild = FALSE) { if (!isset($schema) || $rebuild) { // Try to load the schema from cache. - if (!$rebuild && $cached = cache()->get('schema')) { + if (!$rebuild && $cached = \Drupal::cache()->get('schema')) { $schema = $cached->data; } // Otherwise, rebuild the schema cache. @@ -80,9 +80,9 @@ function drupal_get_complete_schema($rebuild = FALSE) { // Cast the result of hook_schema() to an array, as a NULL return value // would cause array_merge() to set the $schema variable to NULL as well. // That would break modules which use $schema further down the line. - $current = (array) module_invoke($module, 'schema'); + $current = (array) \Drupal::moduleHandler()->invoke($module, 'schema'); // Set 'module' and 'name' keys for each table, and remove descriptions, - // as they needlessly slow down cache()->get() for every single request. + // as they needlessly slow down \Drupal::cache()->get() for every single request. _drupal_schema_initialize($current, $module); $schema = array_merge($schema, $current); } @@ -94,7 +94,7 @@ function drupal_get_complete_schema($rebuild = FALSE) { // If the schema is empty, avoid saving it: some database engines require // the schema to perform queries, and this could lead to infinite loops. if (!empty($schema) && (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL)) { - cache()->set('schema', $schema, Cache::PERMANENT, array('schema' => TRUE)); + \Drupal::cache()->set('schema', $schema, Cache::PERMANENT, array('schema' => TRUE)); } } } @@ -268,7 +268,7 @@ function drupal_uninstall_schema($module) { function drupal_get_schema_unprocessed($module, $table = NULL) { // Load the .install file to get hook_schema. module_load_install($module); - $schema = module_invoke($module, 'schema'); + $schema = \Drupal::moduleHandler()->invoke($module, 'schema'); if (isset($table)) { if (isset($schema[$table])) { diff --git a/core/includes/theme.inc b/core/includes/theme.inc index c65ba3b..e91ecf2 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -72,7 +72,10 @@ * Boolean TRUE if the theme is enabled or is the site administration theme; * FALSE otherwise. * - * @deprecated Use \Drupal::service('access_check.theme')->checkAccess(). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::service('access_check.theme')->checkAccess(). + * + * @see \Drupal\Core\Theme\ThemeAccessCheck::checkAccess(). */ function drupal_theme_access($theme) { if (is_object($theme)) { @@ -362,7 +365,10 @@ function drupal_theme_rebuild() { * names. This element is not set if there are no themes on the system that * declare this theme as their base theme. * - * @deprecated as of Drupal 8.0. Use \Drupal::service('theme_handler')->listInfo(). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::service('theme_handler')->listInfo(). + * + * @see \Drupal\Core\Extension\ThemeHandler::listInfo(). */ function list_themes($refresh = FALSE) { /** @var \Drupal\Core\Extension\ThemeHandler $theme_handler */ @@ -391,7 +397,10 @@ function list_themes($refresh = FALSE) { * Returns an array of all of the theme's ancestors; the first element's value * will be NULL if an error occurred. * - * @deprecated as of Drupal 8.0. Use \Drupal::service('theme_handler')->getBaseThemes(). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::service('theme_handler')->getBaseThemes(). + * + * @see \Drupal\Core\Extension\ThemeHandler::getBaseThemes(). */ function drupal_find_base_themes($themes, $key) { return \Drupal::service('theme_handler')->getBaseThemes($themes, $key); @@ -401,15 +410,15 @@ function drupal_find_base_themes($themes, $key) { * Generates themed output. * * All requests for themed output must go through this function (however, - * calling the theme() function directly is strongly discouraged - see next - * paragraph). It examines the request and routes it to the appropriate + * calling the _theme() function directly is very strongly discouraged - see + * next paragraph). It examines the request and routes it to the appropriate * @link themeable theme function or template @endlink, by checking the theme * registry. * * Avoid calling this function directly. It is preferable to replace direct - * calls to the theme() function with calls to drupal_render() by passing a + * calls to the _theme() function with calls to drupal_render() by passing a * render array with a #theme key to drupal_render(), which in turn calls - * theme(). + * _theme(). * * @section sec_theme_hooks Theme Hooks * Most commonly, the first argument to this function is the name of the theme @@ -473,21 +482,21 @@ function drupal_find_base_themes($themes, $key) { * hook_theme_suggestions_HOOK_alter() or the generic * hook_theme_suggestions_alter(). These alter hooks are used to manipulate an * array of suggested alternate theme hooks to use, in reverse order of - * priority. theme() will use the highest priority implementation that exists. - * If none exists, theme() will use the implementation for the theme hook it was - * called with. These suggestions are similar to and are used for similar - * reasons as calling theme() with an array as the $hook parameter (see below). + * priority. _theme() will use the highest priority implementation that exists. + * If none exists, _theme() will use the implementation for the theme hook it + * was called with. These suggestions are similar to and are used for similar + * reasons as calling _theme() with an array as the $hook parameter (see below). * The difference is whether the suggestions are determined by the code that - * calls theme() or by altering the suggestions via the suggestion alter hooks. + * calls _theme() or by altering the suggestions via the suggestion alter hooks. * * @param $hook * The name of the theme hook to call. If the name contains a * double-underscore ('__') and there isn't an implementation for the full * name, the part before the '__' is checked. This allows a fallback to a - * more generic implementation. For example, if theme('links__node', ...) is + * more generic implementation. For example, if _theme('links__node', ...) is * called, but there is no implementation of that theme hook, then the * 'links' implementation is used. This process is iterative, so if - * theme('links__contextual__node', ...) is called, theme() checks for the + * _theme('links__contextual__node', ...) is called, _theme() checks for the * following implementations, and uses the first one that exists: * - links__contextual__node * - links__contextual @@ -495,7 +504,7 @@ function drupal_find_base_themes($themes, $key) { * This allows themes to create specific theme implementations for named * objects and contexts of otherwise generic theme hooks. The $hook parameter * may also be an array, in which case the first theme hook that has an - * implementation is used. This allows for the code that calls theme() to + * implementation is used. This allows for the code that calls _theme() to * explicitly specify the fallback order in a situation where using the '__' * convention is not desired or is insufficient. * @param $variables @@ -514,13 +523,13 @@ function drupal_find_base_themes($themes, $key) { * @see hook_theme() * @see template_preprocess() */ -function theme($hook, $variables = array()) { +function _theme($hook, $variables = array()) { static $default_attributes; // If called before all modules are loaded, we do not necessarily have a full // theme registry to work with, and therefore cannot process the theme // request properly. See also \Drupal\Core\Theme\Registry::get(). if (!\Drupal::moduleHandler()->isLoaded() && !defined('MAINTENANCE_MODE')) { - throw new Exception(t('theme() may not be called until all modules are loaded.')); + throw new Exception(t('_theme() may not be called until all modules are loaded.')); } /** @var \Drupal\Core\Utility\ThemeRegistry $theme_registry */ @@ -558,7 +567,7 @@ function theme($hook, $variables = array()) { watchdog('theme', 'Theme hook %hook not found.', array('%hook' => $hook), WATCHDOG_WARNING); } // There is no theme implementation for the hook passed. Return FALSE so - // the function calling theme() can differentiate between a hook that + // the function calling _theme() can differentiate between a hook that // exists and renders an empty string and a hook that is not implemented. return FALSE; } @@ -622,7 +631,7 @@ function theme($hook, $variables = array()) { // Invoke hook_theme_suggestions_HOOK(). $suggestions = Drupal::moduleHandler()->invokeAll('theme_suggestions_' . $base_theme_hook, array($variables)); - // If theme() was invoked with a direct theme suggestion like + // If _theme() was invoked with a direct theme suggestion like // '#theme' => 'node__article', add it to the suggestions array before // invoking suggestion alter hooks. if (isset($info['base hook'])) { @@ -638,8 +647,8 @@ function theme($hook, $variables = array()) { \Drupal::moduleHandler()->alter($hooks, $suggestions, $variables, $base_theme_hook); // Check if each suggestion exists in the theme registry, and if so, - // use it instead of the hook that theme() was called with. For example, a - // function may call theme('node', ...), but a module can add + // use it instead of the hook that _theme() was called with. For example, a + // function may call _theme('node', ...), but a module can add // 'node__article' as a suggestion via hook_theme_suggestions_HOOK_alter(), // enabling a theme to have an alternate template file for article nodes. foreach (array_reverse($suggestions) as $suggestion) { @@ -1089,7 +1098,10 @@ function theme_settings_convert_to_config(array $theme_settings, Config $config) * @param $theme_list * An array of theme names. * - * @deprecated as of Drupal 8.0. Use \Drupal::service('theme_handler')->enable(). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::service('theme_handler')->enable(). + * + * @see \Drupal\Core\Extension\ThemeHandler::enable(). */ function theme_enable($theme_list) { \Drupal::service('theme_handler')->enable($theme_list); @@ -1101,7 +1113,10 @@ function theme_enable($theme_list) { * @param $theme_list * An array of theme names. * - * @deprecated as of Drupal 8.0. Use \Drupal::service('theme_handler')->disable(). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::service('theme_handler')->disable(). + * + * @see \Drupal\Core\Extension\ThemeHandler::disable(). */ function theme_disable($theme_list) { \Drupal::service('theme_handler')->disable($theme_list); @@ -1352,7 +1367,7 @@ function template_preprocess_links(&$variables) { * to an empty string, but can be set to NULL for the attribute to be * omitted. Usually, neither omission nor an empty string satisfies * accessibility requirements, so it is strongly encouraged for code - * calling theme('image') to pass a meaningful value for this variable. + * calling _theme('image') to pass a meaningful value for this variable. * - http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8 * - http://www.w3.org/TR/xhtml1/dtds.html * - http://dev.w3.org/html5/spec/Overview.html#alt @@ -1956,10 +1971,10 @@ function _theme_table_cell($cell, $header = FALSE) { * This function is called for theme hooks implemented as templates only, not * for theme hooks implemented as functions. This preprocess function is the * first in the sequence of preprocessing functions that are called when - * preparing variables for a template. See theme() for more details about the + * preparing variables for a template. See _theme() for more details about the * full sequence. * - * @see theme() + * @see _theme() */ function template_preprocess(&$variables, $hook, $info) { // Tell all templates where they are located. @@ -2562,10 +2577,10 @@ function drupal_common_theme() { // HTML 4 and XHTML 1.0 always require an alt attribute. The HTML 5 draft // allows the alt attribute to be omitted in some cases. Therefore, // default the alt attribute to an empty string, but allow code calling - // theme('image') to pass explicit NULL for it to be omitted. Usually, + // _theme('image') to pass explicit NULL for it to be omitted. Usually, // neither omission nor an empty string satisfies accessibility // requirements, so it is strongly encouraged for code calling - // theme('image') to pass a meaningful value for the alt variable. + // _theme('image') to pass a meaningful value for the alt variable. // - http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8 // - http://www.w3.org/TR/xhtml1/dtds.html // - http://dev.w3.org/html5/spec/Overview.html#alt diff --git a/core/includes/update.inc b/core/includes/update.inc index c3bc07a..3431886 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -426,9 +426,9 @@ function update_get_update_list() { // Otherwise, get the list of updates defined by this module. $updates = drupal_get_schema_versions($module); if ($updates !== FALSE) { - // module_invoke returns NULL for nonexisting hooks, so if no updates - // are removed, it will == 0. - $last_removed = module_invoke($module, 'update_last_removed'); + // \Drupal::moduleHandler()->invoke() returns NULL for nonexisting hooks, + // so if no updates are removed, it will == 0. + $last_removed = \Drupal::moduleHandler()->invoke($module, 'update_last_removed'); if ($schema_version < $last_removed) { $ret[$module]['warning'] = '' . $module . ' module cannot be updated. Its schema version is ' . $schema_version . '. Updates up to and including ' . $last_removed . ' have been removed in this release. In order to update ' . $module . ' module, you will first need to upgrade to the last version in which these updates were available.'; continue; diff --git a/core/includes/utility.inc b/core/includes/utility.inc index 023ecb0..b18c941 100644 --- a/core/includes/utility.inc +++ b/core/includes/utility.inc @@ -20,7 +20,8 @@ * @return string * The variable exported in a way compatible to Drupal's coding standards. * - * @deprecated Use \Drupal\Component\Utility\Variable::export(). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Component\Utility\Variable::export(). */ function drupal_var_export($var, $prefix = '') { return Variable::export($var, $prefix); diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index f07ea7f..6127738 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -150,6 +150,16 @@ public static function hasService($id) { } /** + * Indicates if there is a currently active request object. + * + * @return bool + * TRUE if there is a currently active request object, FALSE otherwise. + */ + public static function hasRequest() { + return static::$container && static::$container->has('request') && static::$container->initialized('request') && static::$container->isScopeActive('request'); + } + + /** * Retrieves the currently active request object. * * Note: The use of this wrapper in particular is especially discouraged. Most diff --git a/core/lib/Drupal/Component/Utility/Html.php b/core/lib/Drupal/Component/Utility/Html.php new file mode 100644 index 0000000..bc0a916 --- /dev/null +++ b/core/lib/Drupal/Component/Utility/Html.php @@ -0,0 +1,137 @@ + + + +!html + +EOD; + // PHP's \DOMDocument serialization adds straw whitespace in case the markup + // of the wrapping document contains newlines, so ensure to remove all + // newlines before injecting the actual HTML body to process. + $document = strtr($document, array("\n" => '', '!html' => $html)); + + $dom = new \DOMDocument(); + // Ignore warnings during HTML soup loading. + @$dom->loadHTML($document); + + return $dom; + } + + /** + * Converts the body of a \DOMDocument back to an HTML snippet. + * + * The function serializes the body part of a \DOMDocument back to an (X)HTML + * snippet. The resulting (X)HTML snippet will be properly formatted to be + * compatible with HTML user agents. + * + * @param \DOMDocument $document + * A \DOMDocument object to serialize, only the tags below the first + * node will be converted. + * + * @return string + * A valid (X)HTML snippet, as a string. + */ + public static function serialize(\DOMDocument $document) { + $body_node = $document->getElementsByTagName('body')->item(0); + $html = ''; + + foreach ($body_node->getElementsByTagName('script') as $node) { + static::escapeCdataElement($node); + } + foreach ($body_node->getElementsByTagName('style') as $node) { + static::escapeCdataElement($node, '/*', '*/'); + } + foreach ($body_node->childNodes as $node) { + $html .= $document->saveXML($node); + } + return $html; + } + + /** + * Adds comments around a childNodes as $child_node) { + if ($child_node instanceof \DOMCdataSection) { + $embed_prefix = "\n{$comment_end}\n"; + + // Prevent invalid cdata escaping as this would throw a DOM error. + // This is the same behavior as found in libxml2. + // Related W3C standard: http://www.w3.org/TR/REC-xml/#dt-cdsection + // Fix explanation: http://en.wikipedia.org/wiki/CDATA#Nesting + $data = str_replace(']]>', ']]]]>', $child_node->data); + + $fragment = $node->ownerDocument->createDocumentFragment(); + $fragment->appendXML($embed_prefix . $data . $embed_suffix); + $node->appendChild($fragment); + $node->removeChild($child_node); + } + } + } + +} diff --git a/core/lib/Drupal/Component/Utility/Json.php b/core/lib/Drupal/Component/Utility/Json.php index 54614b5..88e55ae 100644 --- a/core/lib/Drupal/Component/Utility/Json.php +++ b/core/lib/Drupal/Component/Utility/Json.php @@ -40,7 +40,6 @@ public static function encode($variable) { * @return mixed * Returns the decoded string. * - * @see drupal_json_encode() * @ingroup php_wrappers */ public static function decode($string) { diff --git a/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php index 5f920d4..cdaf1d8 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Asset; use Drupal\Core\KeyValueStore\StateInterface; +use Drupal\Component\Utility\Json; /** * Renders JavaScript assets. @@ -67,7 +68,7 @@ public function render(array $js_assets) { switch ($js_asset['type']) { case 'setting': $element['#value_prefix'] = $embed_prefix; - $element['#value'] = 'var drupalSettings = ' . drupal_json_encode(drupal_merge_js_settings($js_asset['data'])) . ";"; + $element['#value'] = 'var drupalSettings = ' . Json::encode(drupal_merge_js_settings($js_asset['data'])) . ";"; $element['#value_suffix'] = $embed_suffix; break; diff --git a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php index 0046918..3bdbc64 100644 --- a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php +++ b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php @@ -38,8 +38,8 @@ * To access your custom cache bin, specify the name of the bin when storing * or retrieving cached data: * @code - * cache('custom_bin')->set($cid, $data, $expire); - * cache('custom_bin')->get($cid); + * \Drupal::cache('custom_bin')->set($cid, $data, $expire); + * \Drupal::cache('custom_bin')->get($cid); * @endcode * * There are two ways to "remove" a cache item: @@ -66,7 +66,7 @@ * the other requests can proceed using the stale value. As soon as the cache * item has been updated, all future requests will use the updated value. * - * @see cache() + * @see \Drupal::cache() * @see \Drupal\Core\Cache\DatabaseBackend */ interface CacheBackendInterface { diff --git a/core/lib/Drupal/Core/Config/BatchConfigImporter.php b/core/lib/Drupal/Core/Config/BatchConfigImporter.php new file mode 100644 index 0000000..b5cf1dc --- /dev/null +++ b/core/lib/Drupal/Core/Config/BatchConfigImporter.php @@ -0,0 +1,88 @@ +validate(); + + if (!$this->lock->acquire(static::ID)) { + // Another process is synchronizing configuration. + throw new ConfigImporterException(sprintf('%s is already importing', static::ID)); + } + $this->totalToProcess = 0; + foreach(array('create', 'delete', 'update') as $op) { + $this->totalToProcess += count($this->getUnprocessed($op)); + } + } + + /** + * Processes batch. + * + * @param array $context. + * The batch context. + */ + public function processBatch(array &$context) { + $operation = $this->getNextOperation(); + if (!empty($operation)) { + $this->process($operation['op'], $operation['name']); + $context['message'] = t('Synchronizing @name.', array('@name' => $operation['name'])); + $context['finished'] = $this->batchProgress(); + } + else { + $context['finished'] = 1; + } + if ($context['finished'] >= 1) { + $this->notify('import'); + // The import is now complete. + $this->lock->release(static::ID); + $this->reset(); + } + } + + /** + * Gets percentage of progress made. + * + * @return float + * The percentage of progress made expressed as a float between 0 and 1. + */ + protected function batchProgress() { + $processed_count = count($this->processed['create']) + count($this->processed['delete']) + count($this->processed['update']); + return $processed_count / $this->totalToProcess; + } + + /** + * Gets the next operation to perform. + * + * @return array|bool + * An array containing the next operation and configuration name to perform + * it on. If there is nothing left to do returns FALSE; + */ + protected function getNextOperation() { + foreach(array('create', 'delete', 'update') as $op) { + $names = $this->getUnprocessed($op); + if (!empty($names)) { + return array( + 'op' => $op, + 'name' => array_shift($names), + ); + } + } + return FALSE; + } +} diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index d159034..b91964e 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Config; +use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\Lock\LockBackendInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -29,7 +30,7 @@ * * @see \Drupal\Core\Config\ConfigImporterEvent */ -class ConfigImporter { +class ConfigImporter extends DependencySerialization { /** * The name used to identify events and the lock. @@ -204,8 +205,15 @@ public function import() { // Another process is synchronizing configuration. throw new ConfigImporterException(sprintf('%s is already importing', static::ID)); } - $this->importInvokeOwner(); - $this->importConfig(); + // First pass deleted, then new, and lastly changed configuration, in order + // to handle dependencies correctly. + // @todo Implement proper dependency ordering using + // https://drupal.org/node/2080823 + foreach (array('delete', 'create', 'update') as $op) { + foreach ($this->getUnprocessed($op) as $name) { + $this->process($op, $name); + } + } // Allow modules to react to a import. $this->notify('import'); @@ -234,63 +242,84 @@ public function validate() { } /** - * Writes an array of config changes from the source to the target storage. + * Processes a configuration change. + * + * @param string $op + * The change operation. + * @param string $name + * The name of the configuration to process. */ - protected function importConfig() { - foreach (array('delete', 'create', 'update') as $op) { - foreach ($this->getUnprocessed($op) as $name) { - $config = new Config($name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); - if ($op == 'delete') { - $config->delete(); - } - else { - $data = $this->storageComparer->getSourceStorage()->read($name); - $config->setData($data ? $data : array()); - $config->save(); - } - $this->setProcessed($op, $name); - } + protected function process($op, $name) { + if (!$this->importInvokeOwner($op, $name)) { + $this->importConfig($op, $name); } } /** + * Writes a configuration change from the source to the target storage. + * + * @param string $op + * The change operation. + * @param string $name + * The name of the configuration to process. + */ + protected function importConfig($op, $name) { + $config = new Config($name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); + if ($op == 'delete') { + $config->delete(); + } + else { + $data = $this->storageComparer->getSourceStorage()->read($name); + $config->setData($data ? $data : array()); + $config->save(); + } + $this->setProcessed($op, $name); + } + + /** * Invokes import* methods on configuration entity storage controllers. * * Allow modules to take over configuration change operations for higher-level * configuration data. * * @todo Add support for other extension types; e.g., themes etc. + * + * @param string $op + * The change operation to get the unprocessed list for, either delete, + * create or update. + * @param string $name + * The name of the configuration to process. + * + * @return bool + * TRUE if the configuration was imported as a configuration entity. FALSE + * otherwise. */ - protected function importInvokeOwner() { - // First pass deleted, then new, and lastly changed configuration, in order - // to handle dependencies correctly. - foreach (array('delete', 'create', 'update') as $op) { - foreach ($this->getUnprocessed($op) as $name) { - // Call to the configuration entity's storage controller to handle the - // configuration change. - $handled_by_module = FALSE; - // Validate the configuration object name before importing it. - // Config::validateName($name); - if ($entity_type = $this->configManager->getEntityTypeIdByName($name)) { - $old_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); - if ($old_data = $this->storageComparer->getTargetStorage()->read($name)) { - $old_config->initWithData($old_data); - } - - $data = $this->storageComparer->getSourceStorage()->read($name); - $new_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); - if ($data !== FALSE) { - $new_config->setData($data); - } - - $method = 'import' . ucfirst($op); - $handled_by_module = $this->configManager->getEntityManager()->getStorageController($entity_type)->$method($name, $new_config, $old_config); - } - if (!empty($handled_by_module)) { - $this->setProcessed($op, $name); - } + protected function importInvokeOwner($op, $name) { + // Call to the configuration entity's storage controller to handle the + // configuration change. + $handled_by_module = FALSE; + // Validate the configuration object name before importing it. + // Config::validateName($name); + if ($entity_type = $this->configManager->getEntityTypeIdByName($name)) { + $old_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); + if ($old_data = $this->storageComparer->getTargetStorage()->read($name)) { + $old_config->initWithData($old_data); + } + + $data = $this->storageComparer->getSourceStorage()->read($name); + $new_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); + if ($data !== FALSE) { + $new_config->setData($data); } + + $method = 'import' . ucfirst($op); + $handled_by_module = $this->configManager->getEntityManager()->getStorageController($entity_type)->$method($name, $new_config, $old_config); + } + if (!empty($handled_by_module)) { + $this->setProcessed($op, $name); + return TRUE; } + return FALSE; } /** diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index cd870f2..e8dcff4 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -35,6 +35,13 @@ public $status = TRUE; /** + * The UUID for this entity. + * + * @var string + */ + public $uuid; + + /** * Whether the config is being created, updated or deleted through the * import process. * diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php new file mode 100644 index 0000000..c72b707 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php @@ -0,0 +1,68 @@ + 'Drupal\Core\Config\Entity\ConfigStorageController', + ); + } + + /** + * {@inheritdoc} + */ + public function getConfigPrefix() { + return isset($this->config_prefix) ? $this->config_prefix : FALSE; + } + + /** + * {@inheritdoc} + */ + public function getBaseTable() { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function getRevisionDataTable() { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function getRevisionTable() { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function getDataTable() { + return FALSE; + } + +} diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 6b717b7..46db8c7 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -389,9 +389,9 @@ public function save(EntityInterface $entity) { */ protected function invokeHook($hook, EntityInterface $entity) { // Invoke the hook. - module_invoke_all($this->entityTypeId . '_' . $hook, $entity); + $this->moduleHandler->invokeAll($this->entityTypeId . '_' . $hook, array($entity)); // Invoke the respective entity-level hook. - module_invoke_all('entity_' . $hook, $entity, $this->entityTypeId); + $this->moduleHandler->invokeAll('entity_' . $hook, array($entity, $this->entityTypeId)); } /** diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Query.php b/core/lib/Drupal/Core/Config/Entity/Query/Query.php index 1df3ffd..7332680 100644 --- a/core/lib/Drupal/Core/Config/Entity/Query/Query.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/Query.php @@ -10,6 +10,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Query\QueryBase; use Drupal\Core\Entity\Query\QueryInterface; @@ -19,13 +20,6 @@ class Query extends QueryBase implements QueryInterface { /** - * Stores the entity manager. - * - * @var \Drupal\Core\Entity\EntityManagerInterface - */ - protected $entityManager; - - /** * The config storage used by the config entity query. * * @var \Drupal\Core\Config\StorageInterface @@ -42,13 +36,11 @@ class Query extends QueryBase implements QueryInterface { /** * Constructs a Query object. * - * @param string $entity_type - * The entity type. + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. * @param string $conjunction * - AND: all of the conditions on the query need to match. * - OR: at least one of the conditions on the query need to match. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager that stores all meta information. * @param \Drupal\Core\Config\StorageInterface $config_storage * The actual config storage which is used to list all config items. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory @@ -56,9 +48,8 @@ class Query extends QueryBase implements QueryInterface { * @param array $namespaces * List of potential namespaces of the classes belonging to this query. */ - function __construct($entity_type, $conjunction, EntityManagerInterface $entity_manager, StorageInterface $config_storage, ConfigFactoryInterface $config_factory, array $namespaces) { + function __construct(EntityTypeInterface $entity_type, $conjunction, StorageInterface $config_storage, ConfigFactoryInterface $config_factory, array $namespaces) { parent::__construct($entity_type, $conjunction, $namespaces); - $this->entityManager = $entity_manager; $this->configStorage = $config_storage; $this->configFactory = $config_factory; } @@ -126,15 +117,14 @@ public function execute() { * Config records keyed by entity IDs. */ protected function loadRecords() { - $entity_type = $this->entityManager->getDefinition($this->getEntityType()); - $prefix = $entity_type->getConfigPrefix() . '.'; + $prefix = $this->entityType->getConfigPrefix() . '.'; $prefix_length = strlen($prefix); // Search the conditions for restrictions on entity IDs. $ids = array(); if ($this->condition->getConjunction() == 'AND') { foreach ($this->condition->conditions() as $condition) { - if (is_string($condition['field']) && $condition['field'] == $entity_type->getKey('id')) { + if (is_string($condition['field']) && $condition['field'] == $this->entityType->getKey('id')) { $operator = $condition['operator'] ?: (is_array($condition['value']) ? 'IN' : '='); if ($operator == '=') { $ids = array($condition['value']); diff --git a/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php b/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php index 6d557cf..f239a66 100644 --- a/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php @@ -10,6 +10,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Query\QueryBase; use Drupal\Core\Entity\Query\QueryException; use Drupal\Core\Entity\Query\QueryFactoryInterface; @@ -57,14 +58,14 @@ public function __construct(StorageInterface $config_storage, ConfigFactoryInter /** * {@inheritdoc} */ - public function get($entity_type, $conjunction, EntityManagerInterface $entity_manager) { - return new Query($entity_type, $conjunction, $entity_manager, $this->configStorage, $this->configFactory, $this->namespaces); + public function get(EntityTypeInterface $entity_type, $conjunction) { + return new Query($entity_type, $conjunction, $this->configStorage, $this->configFactory, $this->namespaces); } /** * {@inheritdoc} */ - public function getAggregate($entity_type, $conjunction, EntityManagerInterface $entity_manager) { + public function getAggregate(EntityTypeInterface $entity_type, $conjunction) { throw new QueryException('Aggregation over configuration entities is not supported'); } diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php index d99ae28..8f4f66c 100644 --- a/core/lib/Drupal/Core/CoreServiceProvider.php +++ b/core/lib/Drupal/Core/CoreServiceProvider.php @@ -54,6 +54,10 @@ public function register(ContainerBuilder $container) { $this->registerModuleHandler($container); $this->registerUuid($container); + // Add the compiler pass that lets service providers modify existing + // service definitions. This pass must come first so that later + // list-building passes are operating on the post-alter services list. + $container->addCompilerPass(new ModifyServiceDefinitionsPass()); $container->addCompilerPass(new RegisterRouteFiltersPass()); // Add a compiler pass for registering event subscribers. $container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING); @@ -75,9 +79,6 @@ public function register(ContainerBuilder $container) { // Add the compiler pass that will process the tagged theme negotiator // service. $container->addCompilerPass(new ThemeNegotiatorPass()); - // Add the compiler pass that lets service providers modify existing - // service definitions. - $container->addCompilerPass(new ModifyServiceDefinitionsPass()); // Add the compiler pass that will process tagged authentication services. $container->addCompilerPass(new RegisterAuthenticationPass()); // Register Twig extensions. diff --git a/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php b/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php new file mode 100644 index 0000000..b99e472 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php @@ -0,0 +1,22 @@ + 'Drupal\Core\Entity\FieldableDatabaseStorageController', + ); + } + + /** + * {@inheritdoc} + */ + public function getConfigPrefix() { + return FALSE; + } + +} diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index 7dfedbc..44ea24b 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -18,7 +18,7 @@ use Drupal\field\FieldUpdateForbiddenException; use Drupal\field\FieldInterface; use Drupal\field\FieldInstanceInterface; -use Drupal\field\Entity\Field; +use Drupal\field\Entity\FieldConfig; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 6a2385f..d100546 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -30,7 +30,7 @@ * Manages entity type plugin definitions. * * Each entity type definition array is set in the entity type's - * annotation and altered by hook_entity_info_alter(). + * annotation and altered by hook_entity_type_alter(). * * The defaults for the plugin definition are provided in * \Drupal\Core\Entity\EntityManagerInterface::defaults. @@ -38,7 +38,7 @@ * @see \Drupal\Core\Entity\Annotation\EntityType * @see \Drupal\Core\Entity\EntityInterface * @see \Drupal\Core\Entity\EntityTypeInterface - * @see hook_entity_info_alter() + * @see hook_entity_type_alter() */ class EntityManager extends PluginManagerBase implements EntityManagerInterface { @@ -134,7 +134,7 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface * The string translationManager. */ public function __construct(\Traversable $namespaces, ContainerInterface $container, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager, TranslationInterface $translation_manager) { - // Allow the plugin definition to be altered by hook_entity_info_alter(). + // Allow the plugin definition to be altered by hook_entity_type_alter(). $this->moduleHandler = $module_handler; $this->cache = $cache; @@ -143,9 +143,9 @@ public function __construct(\Traversable $namespaces, ContainerInterface $contai $this->translationManager = $translation_manager; $this->discovery = new AnnotatedClassDiscovery('Entity', $namespaces, 'Drupal\Core\Entity\Annotation\EntityType'); - $this->discovery = new InfoHookDecorator($this->discovery, 'entity_info'); - $this->discovery = new AlterDecorator($this->discovery, 'entity_info'); - $this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . $this->languageManager->getCurrentLanguage()->id, 'cache', Cache::PERMANENT, array('entity_info' => TRUE)); + $this->discovery = new InfoHookDecorator($this->discovery, 'entity_type_build'); + $this->discovery = new AlterDecorator($this->discovery, 'entity_type'); + $this->discovery = new CacheDecorator($this->discovery, 'entity_type:' . $this->languageManager->getCurrentLanguage()->id, 'cache', Cache::PERMANENT, array('entity_types' => TRUE)); $this->container = $container; } @@ -352,7 +352,7 @@ public function getFieldDefinitions($entity_type_id, $bundle = NULL) { } } - $this->cache->set($cid, $this->entityFieldInfo[$entity_type_id], Cache::PERMANENT, array('entity_info' => TRUE, 'entity_field_info' => TRUE)); + $this->cache->set($cid, $this->entityFieldInfo[$entity_type_id], Cache::PERMANENT, array('entity_types' => TRUE, 'entity_field_info' => TRUE)); } } @@ -414,7 +414,7 @@ public function getAllBundleInfo() { } } $this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo); - $this->cache->set("entity_bundle_info:$langcode", $this->bundleInfo, Cache::PERMANENT, array('entity_info' => TRUE)); + $this->cache->set("entity_bundle_info:$langcode", $this->bundleInfo, Cache::PERMANENT, array('entity_types' => TRUE)); } } diff --git a/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php index cbe2871..3da5abc 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php @@ -12,7 +12,7 @@ * * All entity controller classes specified via the "controllers['storage']" key * returned by \Drupal\Core\Entity\EntityManagerInterface or - * hook_entity_info_alter() have to implement this interface. + * hook_entity_type_alter() have to implement this interface. * * Most simple, SQL-based entity controllers will do better by extending * Drupal\Core\Entity\DatabaseStorageController instead of implementing this diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index b4fe29c..4eae0df 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -164,13 +164,6 @@ class EntityType implements EntityTypeInterface { protected $translatable = FALSE; /** - * Returns the config prefix used by the configuration entity type. - * - * @var string - */ - protected $config_prefix; - - /** * The human-readable name of the type. * * @var string @@ -541,7 +534,7 @@ public function isTranslatable() { * {@inheritdoc} */ public function getConfigPrefix() { - return isset($this->config_prefix) ? $this->config_prefix : FALSE; + return FALSE; } /** diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index 4305c6b..857d3e7 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -10,8 +10,8 @@ /** * Provides an interface for an entity type and its metadata. * - * Additional information can be provided by modules: hook_entity_info() can be - * implemented to define new properties, while hook_entity_info_alter() can be + * Additional information can be provided by modules: hook_entity_type_build() can be + * implemented to define new properties, while hook_entity_type_alter() can be * implemented to alter existing data and fill-in defaults. Module-specific * properties should be documented in the hook implementations defining them. */ diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index bffc731..751f021 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -113,7 +113,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang } // Invoke hook_entity_prepare_view(). - module_invoke_all('entity_prepare_view', $this->entityTypeId, $entities, $displays, $view_mode); + \Drupal::moduleHandler()->invokeAll('entity_prepare_view', array($this->entityTypeId, $entities, $displays, $view_mode)); // Let the displays build their render arrays. foreach ($entities_by_bundle as $bundle => $bundle_entities) { @@ -225,8 +225,8 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la foreach ($entities as $key => $entity) { $entity_view_mode = isset($entity->content['#view_mode']) ? $entity->content['#view_mode'] : $view_mode; $display = $displays[$entity_view_mode][$entity->bundle()]; - module_invoke_all($view_hook, $entity, $display, $entity_view_mode, $langcode); - module_invoke_all('entity_view', $entity, $display, $entity_view_mode, $langcode); + \Drupal::moduleHandler()->invokeAll($view_hook, array($entity, $display, $entity_view_mode, $langcode)); + \Drupal::moduleHandler()->invokeAll('entity_view', array($entity, $display, $entity_view_mode, $langcode)); $build[$key] = $entity->content; // We don't need duplicate rendering info in $entity->content. diff --git a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php index ca9e694..6a1c8f8 100644 --- a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php @@ -17,7 +17,7 @@ use Drupal\field\FieldUpdateForbiddenException; use Drupal\field\FieldInterface; use Drupal\field\FieldInstanceInterface; -use Drupal\field\Entity\Field; +use Drupal\field\Entity\FieldConfig; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -1099,7 +1099,7 @@ public function onBundleRename($bundle, $bundle_new) { // We need to account for deleted fields and instances. The method runs // before the instance definitions are updated, so we need to fetch them // using the old bundle name. - $instances = entity_load_multiple_by_properties('field_instance', array('entity_type' => $this->entityTypeId, 'bundle' => $bundle, 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $this->entityTypeId, 'bundle' => $bundle, 'include_deleted' => TRUE)); foreach ($instances as $instance) { $field = $instance->getField(); $table_name = static::_fieldTableName($field); @@ -1451,7 +1451,7 @@ static public function _fieldIndexName(FieldInterface $field, $index) { * unique among all other fields. */ static public function _fieldColumnName(FieldInterface $field, $column) { - return in_array($column, Field::getReservedColumns()) ? $column : $field->getName() . '_' . $column; + return in_array($column, FieldConfig::getReservedColumns()) ? $column : $field->getName() . '_' . $column; } } diff --git a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php index 22b54a3..17fd274 100644 --- a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php +++ b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php @@ -134,7 +134,7 @@ protected function loadFieldItems(array $entities) { foreach ($entities as $id => $entity) { $cids[] = "field:{$this->entityTypeId}:$id"; } - $cache = cache('field')->getMultiple($cids); + $cache = \Drupal::cache('field')->getMultiple($cids); // Put the cached field values back into the entities and remove them from // the list of entities to query. foreach ($entities as $id => $entity) { @@ -183,7 +183,7 @@ protected function loadFieldItems(array $entities) { } } $cid = "field:{$this->entityTypeId}:$id"; - cache('field')->set($cid, $data); + \Drupal::cache('field')->set($cid, $data); } } } @@ -207,7 +207,7 @@ protected function saveFieldItems(EntityInterface $entity, $update = TRUE) { if ($update) { $entity_type = $entity->getEntityType(); if ($entity_type->isFieldDataCacheable()) { - cache('field')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id()); + \Drupal::cache('field')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id()); } } } @@ -227,7 +227,7 @@ protected function deleteFieldItems(EntityInterface $entity) { $entity_type = $entity->getEntityType(); if ($entity_type->isFieldDataCacheable()) { - cache('field')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id()); + \Drupal::cache('field')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id()); } } diff --git a/core/lib/Drupal/Core/Entity/Query/QueryBase.php b/core/lib/Drupal/Core/Entity/Query/QueryBase.php index 3ba51ec..e98755a 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryBase.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php @@ -9,11 +9,12 @@ use Drupal\Core\Database\Query\PagerSelectExtender; use Drupal\Core\Entity\EntityStorageControllerInterface; +use Drupal\Core\Entity\EntityTypeInterface; /** * The base entity query class. */ -abstract class QueryBase { +abstract class QueryBase implements QueryInterface { /** * The entity type this query runs against. @@ -23,6 +24,13 @@ protected $entityTypeId; /** + * Information about the entity type. + * + * @var \Drupal\Core\Entity\EntityTypeInterface + */ + protected $entityType; + + /** * The list of sorts. * * @var array @@ -127,9 +135,18 @@ /** * Constructs this object. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. + * @param string $conjunction + * - AND: all of the conditions on the query need to match. + * - OR: at least one of the conditions on the query need to match. + * @param array $namespaces + * List of potential namespaces of the classes belonging to this query. */ - public function __construct($entity_type, $conjunction, array $namespaces) { - $this->entityTypeId = $entity_type; + public function __construct(EntityTypeInterface $entity_type, $conjunction, array $namespaces) { + $this->entityTypeId = $entity_type->id(); + $this->entityType = $entity_type; $this->conjunction = $conjunction; $this->namespaces = $namespaces; $this->condition = $this->conditionGroupFactory($conjunction); @@ -139,9 +156,9 @@ public function __construct($entity_type, $conjunction, array $namespaces) { } /** - * Implements \Drupal\Core\Entity\Query\QueryInterface::getEntityType(). + * {@inheritdoc} */ - public function getEntityType() { + public function getEntityTypeId() { return $this->entityTypeId; } diff --git a/core/lib/Drupal/Core/Entity/Query/QueryFactory.php b/core/lib/Drupal/Core/Entity/Query/QueryFactory.php index 27bccbd..fff7c864 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryFactory.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryFactory.php @@ -35,8 +35,8 @@ public function __construct(EntityManagerInterface $entity_manager) { /** * Returns a query object for a given entity type. * - * @param string $entity_type - * The entity type. + * @param string $entity_type_id + * The entity type ID. * @param string $conjunction * - AND: all of the conditions on the query need to match. * - OR: at least one of the conditions on the query need to match. @@ -44,16 +44,16 @@ public function __construct(EntityManagerInterface $entity_manager) { * @return \Drupal\Core\Entity\Query\QueryInterface * The query object that can query the given entity type. */ - public function get($entity_type, $conjunction = 'AND') { - $service_name = $this->entityManager->getStorageController($entity_type)->getQueryServicename(); - return $this->container->get($service_name)->get($entity_type, $conjunction, $this->entityManager); + public function get($entity_type_id, $conjunction = 'AND') { + $service_name = $this->entityManager->getStorageController($entity_type_id)->getQueryServicename(); + return $this->container->get($service_name)->get($this->entityManager->getDefinition($entity_type_id), $conjunction); } /** * Returns an aggregated query object for a given entity type. * - * @param string $entity_type - * The entity type. + * @param string $entity_type_id + * The entity type ID. * @param string $conjunction * - AND: all of the conditions on the query need to match. * - OR: at least one of the conditions on the query need to match. @@ -61,9 +61,9 @@ public function get($entity_type, $conjunction = 'AND') { * @return \Drupal\Core\Entity\Query\QueryAggregateInterface * The aggregated query object that can query the given entity type. */ - public function getAggregate($entity_type, $conjunction = 'AND') { - $service_name = $this->entityManager->getStorageController($entity_type)->getQueryServicename(); - return $this->container->get($service_name)->getAggregate($entity_type, $conjunction, $this->entityManager); + public function getAggregate($entity_type_id, $conjunction = 'AND') { + $service_name = $this->entityManager->getStorageController($entity_type_id)->getQueryServicename(); + return $this->container->get($service_name)->getAggregate($this->entityManager->getDefinition($entity_type_id), $conjunction); } } diff --git a/core/lib/Drupal/Core/Entity/Query/QueryFactoryInterface.php b/core/lib/Drupal/Core/Entity/Query/QueryFactoryInterface.php index de22118..c42635c 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryFactoryInterface.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryFactoryInterface.php @@ -6,8 +6,7 @@ */ namespace Drupal\Core\Entity\Query; - -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeInterface; /** * Defines an interface for QueryFactory classes. @@ -17,35 +16,29 @@ /** * Instantiates an entity query for a given entity type. * - * @param string $entity_type - * The entity type for the query. + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. * @param string $conjunction * The operator to use to combine conditions: 'AND' or 'OR'. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager that handles the entity type. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager that handles the entity type. * * @return \Drupal\Core\Entity\Query\QueryInterface * An entity query for a specific configuration entity type. */ - public function get($entity_type, $conjunction, EntityManagerInterface $entity_manager); + public function get(EntityTypeInterface $entity_type, $conjunction); /** * Returns a aggregation query object for a given entity type. * - * @param string $entity_type - * The entity type. + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. * @param string $conjunction * - AND: all of the conditions on the query need to match. * - OR: at least one of the conditions on the query need to match. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager that handles the entity type. * * @throws \Drupal\Core\Entity\Query\QueryException * @return \Drupal\Core\Entity\Query\QueryAggregateInterface * The query object that can query the given entity type. */ - public function getAggregate($entity_type, $conjunction, EntityManagerInterface $entity_manager); + public function getAggregate(EntityTypeInterface $entity_type, $conjunction); } diff --git a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php index 8f2ed21..4a9420b 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php @@ -19,11 +19,11 @@ interface QueryInterface extends AlterableInterface { /** - * Gets the entity type for this query. + * Gets the ID of the entity type for this query. * * @return string */ - public function getEntityType(); + public function getEntityTypeId(); /** * Add a condition to the query or a condition group. diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php index 7d7d901..407cef5 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php @@ -10,6 +10,7 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Query\QueryBase; use Drupal\Core\Entity\Query\QueryException; use Drupal\Core\Entity\Query\QueryInterface; @@ -20,13 +21,6 @@ class Query extends QueryBase implements QueryInterface { /** - * The entity type definition. - * - * @var \Drupal\Core\Entity\EntityTypeInterface - */ - protected $entityType; - - /** * The build sql select query. * * @var \Drupal\Core\Database\Query\SelectInterface @@ -68,19 +62,18 @@ class Query extends QueryBase implements QueryInterface { /** * Constructs a query object. * - * @param string $entity_type - * The entity type. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager service. + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. * @param string $conjunction * - AND: all of the conditions on the query need to match. * - OR: at least one of the conditions on the query need to match. * @param \Drupal\Core\Database\Connection $connection * The database connection to run the query against. + * @param array $namespaces + * List of potential namespaces of the classes belonging to this query. */ - public function __construct($entity_type, EntityManagerInterface $entity_manager, $conjunction, Connection $connection, array $namespaces) { + public function __construct(EntityTypeInterface $entity_type, $conjunction, Connection $connection, array $namespaces) { parent::__construct($entity_type, $conjunction, $namespaces); - $this->entityManager = $entity_manager; $this->connection = $connection; } @@ -107,8 +100,6 @@ public function execute() { * Returns the called object. */ protected function prepare() { - $entity_type = $this->entityTypeId; - $this->entityType = $this->entityManager->getDefinition($entity_type); if (!$base_table = $this->entityType->getBaseTable()) { throw new QueryException("No base table, invalid query."); } @@ -117,7 +108,7 @@ protected function prepare() { $simple_query = FALSE; } $this->sqlQuery = $this->connection->select($base_table, 'base_table', array('conjunction' => $this->conjunction)); - $this->sqlQuery->addMetaData('entity_type', $entity_type); + $this->sqlQuery->addMetaData('entity_type', $this->entityTypeId); $id_field = $this->entityType->getKey('id'); // Add the key field for fetchAllKeyed(). if (!$revision_field = $this->entityType->getKey('revision')) { @@ -135,7 +126,7 @@ protected function prepare() { $this->sqlFields["base_table.$id_field"] = array('base_table', $id_field); } if ($this->accessCheck) { - $this->sqlQuery->addTag($entity_type . '_access'); + $this->sqlQuery->addTag($this->entityTypeId . '_access'); } $this->sqlQuery->addTag('entity_query'); $this->sqlQuery->addTag('entity_query_' . $this->entityTypeId); diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/QueryFactory.php b/core/lib/Drupal/Core/Entity/Query/Sql/QueryFactory.php index 13e269a..4b7de43 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/QueryFactory.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/QueryFactory.php @@ -9,6 +9,7 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Query\QueryBase; use Drupal\Core\Entity\Query\QueryFactoryInterface; @@ -46,37 +47,19 @@ public function __construct(Connection $connection) { } /** - * Constructs a entity query for a certain entity type. - * - * @param string $entity_type - * The entity type. - * @param string $conjunction - * - AND: all of the conditions on the query need to match. - * - OR: at least one of the conditions on the query need to match. - * - * @return \Drupal\Core\Entity\Query\Sql\Query - * The factored query. + * {@inheritdoc} */ - public function get($entity_type, $conjunction, EntityManagerInterface $entity_manager) { + public function get(EntityTypeInterface $entity_type, $conjunction) { $class = QueryBase::getClass($this->namespaces, 'Query'); - return new $class($entity_type, $entity_manager, $conjunction, $this->connection, $this->namespaces); + return new $class($entity_type, $conjunction, $this->connection, $this->namespaces); } /** - * Constructs a entity aggregation query for a certain entity type. - * - * @param string $entity_type - * The entity type. - * @param string $conjunction - * - AND: all of the conditions on the query need to match. - * - OR: at least one of the conditions on the query need to match. - * - * @return \Drupal\Core\Entity\Query\Sql\QueryAggregate - * The factored aggregation query. + * {@inheritdoc} */ - public function getAggregate($entity_type, $conjunction, EntityManagerInterface $entity_manager) { + public function getAggregate(EntityTypeInterface $entity_type, $conjunction) { $class = QueryBase::getClass($this->namespaces, 'QueryAggregate'); - return new $class($entity_type, $entity_manager, $conjunction, $this->connection, $this->namespaces); + return new $class($entity_type, $conjunction, $this->connection, $this->namespaces); } } diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index add9c73..0621500 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -12,7 +12,7 @@ use Drupal\Core\Entity\FieldableDatabaseStorageController; use Drupal\Core\Entity\Plugin\DataType\EntityReference; use Drupal\Core\Entity\Query\QueryException; -use Drupal\field\Entity\Field; +use Drupal\field\Entity\FieldConfig; use Drupal\field\Field as FieldInfo; /** @@ -118,7 +118,7 @@ public function addField($field, $type, $langcode) { $next = $specifiers[$key + 1]; // Is this a field column? $columns = $field->getColumns(); - if (isset($columns[$next]) || in_array($next, Field::getReservedColumns())) { + if (isset($columns[$next]) || in_array($next, FieldConfig::getReservedColumns())) { // Use it. $column = $next; // Do not process it again. diff --git a/core/lib/Drupal/Core/Extension/UpdateModuleHandler.php b/core/lib/Drupal/Core/Extension/UpdateModuleHandler.php index a8334b8..1b8a466 100644 --- a/core/lib/Drupal/Core/Extension/UpdateModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/UpdateModuleHandler.php @@ -24,7 +24,7 @@ public function getImplementations($hook) { if (substr($hook, -6) === '_alter') { return array(); } - // theme() is called during updates and fires hooks, so whitelist the + // _theme() is called during updates and fires hooks, so whitelist the // system module. if (substr($hook, 0, 6) == 'theme_') { return array('system'); @@ -49,7 +49,7 @@ public function getImplementations($hook) { // This is called during rebuild to find testing themes. case 'system_theme_info': // Those are needed by user_access() to check access on update.php. - case 'entity_info': + case 'entity_type_build': case 'entity_load': case 'user_role_load': return array(); diff --git a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php index aba828f..8146d9e 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php @@ -27,18 +27,19 @@ * It is up to the class implementing this interface to manage where the * information comes from. For example, field.module provides an implementation * based on two levels of configuration. It allows the site administrator to add - * custom fields to any entity type and bundle via the "field_entity" and - * "field_instance" configuration entities. The former for storing configuration - * that is independent of which entity type and bundle the field is added to, - * and the latter for storing configuration that is specific to the entity type - * and bundle. The class that implements "field_instance" configuration entities - * also implements this interface, returning information from either itself, or - * from the corresponding "field_entity" configuration, as appropriate. + * custom fields to any entity type and bundle via the "field_config" and + * "field_instance_config" configuration entities. The former for storing + * configuration that is independent of which entity type and bundle the field + * is added to, and the latter for storing configuration that is specific to the + * entity type and bundle. The class that implements "field_instance_config" + * configuration entities also implements this interface, returning information + * from either itself, or from the corresponding "field_config" configuration, + * as appropriate. * * However, entity base fields, such as $node->title, are not managed by - * field.module and its "field_entity"/"field_instance" configuration entities. - * Therefore, their definitions are provided by different objects based on the - * class \Drupal\Core\Field\FieldDefinition, which implements this + * field.module and its "field_config"/"field_instance_config" configuration + * entities. Therefore, their definitions are provided by different objects + * based on the class \Drupal\Core\Field\FieldDefinition, which implements this * interface as well. * * Field definitions may fully define a concrete data object (e.g., diff --git a/core/lib/Drupal/Core/Field/WidgetBase.php b/core/lib/Drupal/Core/Field/WidgetBase.php index e73a34f..58e5d25 100644 --- a/core/lib/Drupal/Core/Field/WidgetBase.php +++ b/core/lib/Drupal/Core/Field/WidgetBase.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\SortArray; +use Drupal\Component\Utility\String; use Symfony\Component\Validator\ConstraintViolationInterface; /** @@ -74,7 +75,7 @@ public function form(FieldItemListInterface $items, array &$form, array &$form_s if ($this->handlesMultipleValues() || isset($get_delta)) { $delta = isset($get_delta) ? $get_delta : 0; $element = array( - '#title' => check_plain($this->fieldDefinition->getLabel()), + '#title' => String::checkPlain($this->fieldDefinition->getLabel()), '#description' => field_filter_xss(\Drupal::token()->replace($this->fieldDefinition->getDescription())), ); $element = $this->formSingleElement($items, $delta, $element, $form, $form_state); @@ -161,7 +162,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f $id_prefix = implode('-', array_merge($parents, array($field_name))); $wrapper_id = drupal_html_id($id_prefix . '-add-more-wrapper'); - $title = check_plain($this->fieldDefinition->getLabel()); + $title = String::checkPlain($this->fieldDefinition->getLabel()); $description = field_filter_xss(\Drupal::token()->replace($this->fieldDefinition->getDescription())); $elements = array(); diff --git a/core/lib/Drupal/Core/Menu/LocalActionManager.php b/core/lib/Drupal/Core/Menu/LocalActionManager.php index 32ae80e..79e40c9 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -11,6 +11,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; +use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Menu\LocalActionInterface; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Component\Plugin\Discovery\ProcessDecorator; @@ -94,7 +95,7 @@ class LocalActionManager extends DefaultPluginManager { /** * The plugin instances. * - * @var array + * @var \Drupal\Core\Menu\LocalActionInterface[] */ protected $instances = array(); @@ -112,12 +113,14 @@ class LocalActionManager extends DefaultPluginManager { * The module handler. * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * Cache backend instance to use. - * @param \Drupal\Core\Language\LanguageManager $language_manager + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. * @param \Drupal\Core\Access\AccessManager $access_manager * The access manager. + * @param \Drupal\Core\Session\AccountInterface $account + * The current user. */ - public function __construct(ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManager $language_manager, AccessManager $access_manager, AccountInterface $account) { + public function __construct(ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, AccessManager $access_manager, AccountInterface $account) { // Skip calling the parent constructor, since that assumes annotation-based // discovery. $this->discovery = new YamlDiscovery('local_actions', $module_handler->getModuleDirectories()); @@ -179,10 +182,10 @@ public function getActionsForRoute($route_appears) { } } $links = array(); - foreach ($this->instances[$route_appears] as $plugin) { + foreach ($this->instances[$route_appears] as $plugin_id => $plugin) { $route_name = $plugin->getRouteName(); $route_parameters = $plugin->getRouteParameters($this->request); - $links[$route_name] = array( + $links[$plugin_id] = array( '#theme' => 'menu_local_action', '#link' => array( 'title' => $this->getTitle($plugin), diff --git a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php index 9f3fbf0..667bebe 100644 --- a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php +++ b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Plugin; -use Drupal\Component\Plugin\ContextAwarePluginBase as PluginBase; +use Drupal\Component\Plugin\ContextAwarePluginBase as ComponentContextAwarePluginBase; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Plugin\Context\Context; use Drupal\Component\Plugin\Discovery\DiscoveryInterface; @@ -20,7 +20,7 @@ * the Context class. This code is exactly the same as what is in Component * ContextAwarePluginBase but it is using a different Context class. */ -abstract class ContextAwarePluginBase extends PluginBase { +abstract class ContextAwarePluginBase extends ComponentContextAwarePluginBase { /** * Override of \Drupal\Component\Plugin\ContextAwarePluginBase::__construct(). diff --git a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php index a2ce7d1..5c42a81 100644 --- a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php +++ b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php @@ -77,7 +77,7 @@ * * @throws \Drupal\Core\Routing\GeneratorNotInitializedException. * - * @deprecated since version 8.0 + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. * System paths should not be used - use route names and parameters. */ public function generateFromPath($path = NULL, $options = array()); @@ -94,7 +94,7 @@ public function generateFromPath($path = NULL, $options = array()); * @return string * The internal Drupal path corresponding to the route. * - * @deprecated since version 8.0 + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. * System paths should not be used - use route names and parameters. */ public function getPathFromRoute($name, $parameters = array()); diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index 24c9084..2bbf3c9 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -36,7 +36,7 @@ class TwigEnvironment extends \Twig_Environment { */ public function __construct(\Twig_LoaderInterface $loader = NULL, $options = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { // @todo Pass as arguments from the DIC. - $this->cache_object = cache(); + $this->cache_object = \Drupal::cache(); // Set twig path namespace for themes and modules. $namespaces = $module_handler->getModuleList(); diff --git a/core/lib/Drupal/Core/Theme/Registry.php b/core/lib/Drupal/Core/Theme/Registry.php index b0fed73..1d3cb22 100644 --- a/core/lib/Drupal/Core/Theme/Registry.php +++ b/core/lib/Drupal/Core/Theme/Registry.php @@ -59,12 +59,12 @@ class Registry implements DestructableInterface { * from; e.g., 'module' for theme hook 'node' of Node module. * - name: The name of the extension the original theme hook originates * from; e.g., 'node' for theme hook 'node' of Node module. - * - theme path: The effective path_to_theme() during theme(), available as + * - theme path: The effective path_to_theme() during _theme(), available as * 'directory' variable in templates. * functions, it should point to the respective theme. For templates, * it should point to the directory that contains the template. * - includes: (optional) An array of include files to load when the theme - * hook is executed by theme(). + * hook is executed by _theme(). * - file: (optional) A filename to add to 'includes', either prefixed with * the value of 'path', or the path of the extension implementing * hook_theme(). @@ -291,7 +291,7 @@ public function getBaseHook($hook) { * for base hooks (e.g., 'block__node' for the base hook 'block') need to be * determined based on the full registry and classified as 'base hook'. * - * @see theme() + * @see _theme() * @see hook_theme_registry_alter() * * @return \Drupal\Core\Utility\ThemeRegistry @@ -374,7 +374,7 @@ protected function build() { * in hook_theme(). If there is more than one implementation and * 'render element' is not specified in a later one, then the previous * definition is kept. - * - 'preprocess functions': See theme() for detailed documentation. + * - 'preprocess functions': See _theme() for detailed documentation. * @param string $name * The name of the module, theme engine, base theme engine, theme or base * theme implementing hook_theme(). @@ -391,7 +391,7 @@ protected function build() { * The directory where $name is. For example, modules/system or * themes/bartik. * - * @see theme() + * @see _theme() * @see hook_theme() * @see list_themes() */ @@ -486,7 +486,7 @@ protected function processExtension(&$cache, $name, $type, $theme, $path) { } foreach ($prefixes as $prefix) { // Only use non-hook-specific variable preprocessors for theming - // hooks implemented as templates. See theme(). + // hooks implemented as templates. See _theme(). if (isset($info['template']) && function_exists($prefix . '_preprocess')) { $info['preprocess functions'][] = $prefix . '_preprocess'; } @@ -522,7 +522,7 @@ protected function processExtension(&$cache, $name, $type, $theme, $path) { $cache[$hook]['preprocess functions'] = array(); } // Only use non-hook-specific variable preprocessors for theme hooks - // implemented as templates. See theme(). + // implemented as templates. See _theme(). if (isset($info['template']) && function_exists($name . '_preprocess')) { $cache[$hook]['preprocess functions'][] = $name . '_preprocess'; } diff --git a/core/lib/Drupal/Core/Utility/CacheArray.php b/core/lib/Drupal/Core/Utility/CacheArray.php index 2323756..fb46569 100644 --- a/core/lib/Drupal/Core/Utility/CacheArray.php +++ b/core/lib/Drupal/Core/Utility/CacheArray.php @@ -61,28 +61,29 @@ * procedural code. Extending classes may wish to alter this behavior, for * example by overriding offsetSet() and adding an automatic call to persist(). * - * @deprecated as of Drupal 8.0. Use \Drupal\Core\Cache\CacheCollector instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\Core\Cache\CacheCollector. * * @see SchemaCache */ abstract class CacheArray implements \ArrayAccess { /** - * A cid to pass to cache()->set() and cache()->get(). + * A cid to pass to \Drupal::cache()->set() and \Drupal::cache()->get(). * * @var string */ protected $cid; /** - * A tags array to pass to cache()->set(). + * A tags array to pass to \Drupal::cache()->set(). * * @var array */ protected $tags; /** - * A bin to pass to cache()->set() and cache()->get(). + * A bin to pass to \Drupal::cache()->set() and \Drupal::cache()->get(). * * @var string */ @@ -117,7 +118,7 @@ public function __construct($cid, $bin, $tags = array()) { $this->bin = $bin; $this->tags = $tags; - if ($cached = cache($bin)->get($this->cid)) { + if ($cached = \Drupal::cache($bin)->get($this->cid)) { $this->storage = $cached->data; } } @@ -202,10 +203,10 @@ protected function set($data, $lock = TRUE) { // To implement locking for cache misses, override __construct(). $lock_name = $this->cid . ':' . $this->bin; if (!$lock || lock()->acquire($lock_name)) { - if ($cached = cache($this->bin)->get($this->cid)) { + if ($cached = \Drupal::cache($this->bin)->get($this->cid)) { $data = $cached->data + $data; } - cache($this->bin)->set($this->cid, $data, Cache::PERMANENT, $this->tags); + \Drupal::cache($this->bin)->set($this->cid, $data, Cache::PERMANENT, $this->tags); if ($lock) { lock()->release($lock_name); } @@ -218,7 +219,7 @@ protected function set($data, $lock = TRUE) { public function clear() { $this->storage = array(); $this->keysToPersist = array(); - cache($this->bin)->delete($this->cid); + \Drupal::cache($this->bin)->delete($this->cid); } /** diff --git a/core/lib/Drupal/Core/Utility/ThemeRegistry.php b/core/lib/Drupal/Core/Utility/ThemeRegistry.php index 8d3e1f8..dbd44e9 100644 --- a/core/lib/Drupal/Core/Utility/ThemeRegistry.php +++ b/core/lib/Drupal/Core/Utility/ThemeRegistry.php @@ -26,7 +26,7 @@ class ThemeRegistry extends CacheCollector implements DestructableInterface { /** * Whether the partial registry can be persisted to the cache. * - * This is only allowed if all modules and the request method is GET. theme() + * This is only allowed if all modules and the request method is GET. _theme() * should be very rarely called on POST requests and this avoids polluting * the runtime cache. */ diff --git a/core/lib/Drupal/Core/Utility/Token.php b/core/lib/Drupal/Core/Utility/Token.php index 29fef78..e612de8 100644 --- a/core/lib/Drupal/Core/Utility/Token.php +++ b/core/lib/Drupal/Core/Utility/Token.php @@ -108,8 +108,8 @@ public function __construct(ModuleHandlerInterface $module_handler) { * - sanitize: A boolean flag indicating that tokens should be sanitized for * display to a web browser. Defaults to TRUE. Developers who set this * option to FALSE assume responsibility for running filter_xss(), - * check_plain() or other appropriate scrubbing functions before displaying - * data to users. + * String::checkPlain() or other appropriate scrubbing functions before + * displaying data to users. * * @return string * Text with tokens replaced. @@ -200,7 +200,7 @@ public function scan($text) { * encoding or truncation to a specific length. * - sanitize: A boolean flag indicating that tokens should be sanitized for * display to a web browser. Developers who set this option to FALSE assume - * responsibility for running filter_xss(), check_plain() or other + * responsibility for running filter_xss(), String::checkPlain() or other * appropriate scrubbing functions before displaying data to users. * * @return array diff --git a/core/modules/action/action.module b/core/modules/action/action.module index cc6821b..07e7b48 100644 --- a/core/modules/action/action.module +++ b/core/modules/action/action.module @@ -71,11 +71,11 @@ function action_menu_link_defaults() { } /** - * Implements hook_entity_info(). + * Implements hook_entity_type_build(). */ -function action_entity_info(&$entity_info) { - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ - $entity_info['action'] +function action_entity_type_build(array &$entity_types) { + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ + $entity_types['action'] ->setFormClass('add', 'Drupal\action\ActionAddFormController') ->setFormClass('edit', 'Drupal\action\ActionEditFormController') ->setFormClass('delete', 'Drupal\action\Form\ActionDeleteForm') diff --git a/core/modules/action/action.views_execution.inc b/core/modules/action/action.views_execution.inc index 859cffd..32bc883 100644 --- a/core/modules/action/action.views_execution.inc +++ b/core/modules/action/action.views_execution.inc @@ -5,12 +5,14 @@ * Provides views runtime hooks for action.module. */ +use Drupal\Component\Utility\String; + /** * Implements hook_views_form_substitutions(). */ function action_views_form_substitutions() { - // Views check_plain()s the column label, so we need to match that. - $select_all_placeholder = check_plain(''); + // Views String::checkPlain()s the column label, so we need to match that. + $select_all_placeholder = String::checkPlain(''); $select_all = array( '#type' => 'checkbox', '#default_value' => FALSE, diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc deleted file mode 100644 index 95b6f6f..0000000 --- a/core/modules/aggregator/aggregator.pages.inc +++ /dev/null @@ -1,39 +0,0 @@ -fid identifying the feed used to - * as filter. - * The $data parameter is not used when $type is 'sum'. - * @param int $limit - * (optional) The number of records to return. Defaults to 20. - * - * @deprecated Use \Drupal\aggregator\ItemStorageController::loadAll() for - * loading all feed items, \Drupal\aggregator\ItemStorageController::loadByFeed() - * - * @return \Drupal\aggregator\ItemInterface[] - * An array of the feed items. - */ -function aggregator_load_feed_items($type, $data = NULL, $limit = 20) { - $storage_controller = \Drupal::entityManager()->getStorageController('aggregator_item'); - switch ($type) { - case 'sum': - return $storage_controller->loadAll($limit); - - case 'source': - return $storage_controller->loadByFeed($data->id(), $limit); - } -} diff --git a/core/modules/aggregator/aggregator.theme.inc b/core/modules/aggregator/aggregator.theme.inc index 5531dd6..ef43d44 100644 --- a/core/modules/aggregator/aggregator.theme.inc +++ b/core/modules/aggregator/aggregator.theme.inc @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\Component\Utility\String; /** * Prepares variables for aggregator item templates. @@ -21,7 +22,7 @@ function template_preprocess_aggregator_item(&$variables) { $item = $variables['aggregator_item']; $variables['feed_url'] = check_url($item->getLink()); - $variables['feed_title'] = check_plain($item->getTitle()); + $variables['feed_title'] = String::checkPlain($item->getTitle()); $variables['content'] = aggregator_filter_xss($item->getDescription()); $variables['source_url'] = ''; @@ -29,7 +30,7 @@ function template_preprocess_aggregator_item(&$variables) { $fid = $item->getFeedId(); if (isset($item->ftitle) && $fid !== NULL) { $variables['source_url'] = url('aggregator/sources/' . $fid); - $variables['source_title'] = check_plain($item->ftitle); + $variables['source_title'] = String::checkPlain($item->ftitle); } if (date('Ymd', $item->getPostedTime()) == date('Ymd')) { $variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->getPostedTime()))); @@ -59,12 +60,12 @@ function theme_aggregator_page_opml($variables) { $output = "\n"; $output .= "\n"; $output .= "\n"; - $output .= '' . check_plain(\Drupal::config('system.site')->get('name')) . "\n"; + $output .= '' . String::checkPlain(\Drupal::config('system.site')->get('name')) . "\n"; $output .= '' . gmdate(DATE_RFC2822, REQUEST_TIME) . "\n"; $output .= "\n"; $output .= "\n"; foreach ($feeds as $feed) { - $output .= '\n"; + $output .= '\n"; } $output .= "\n"; $output .= "\n"; @@ -84,7 +85,7 @@ function theme_aggregator_page_opml($variables) { * - summary_items: An array of feed items. */ function template_preprocess_aggregator_summary_items(&$variables) { - $variables['title'] = check_plain($variables['source'] instanceof EntityInterface ? $variables['source']->label() : $variables['source']->title); + $variables['title'] = String::checkPlain($variables['source'] instanceof EntityInterface ? $variables['source']->label() : $variables['source']->title); $summary_items = array(); foreach (element_children($variables['summary_items']) as $key) { $summary_items[] = $variables['summary_items'][$key]; @@ -109,7 +110,7 @@ function template_preprocess_aggregator_summary_items(&$variables) { function template_preprocess_aggregator_summary_item(&$variables) { $item = $variables['aggregator_item']; - $variables['url'] = l(check_plain($item->label()), check_url(url($item->getLink(), array('absolute' => TRUE))), array( + $variables['url'] = l(String::checkPlain($item->label()), check_url(url($item->getLink(), array('absolute' => TRUE))), array( 'attributes' => array( 'class' => array('feed-item-url'), ), @@ -186,5 +187,5 @@ function template_preprocess_aggregator_feed_source(&$variables) { function template_preprocess_aggregator_block_item(&$variables) { // Display the external link to the item. $variables['url'] = check_url($variables['item']->link); - $variables['title'] = check_plain($variables['item']->title); + $variables['title'] = String::checkPlain($variables['item']->title); } diff --git a/core/modules/aggregator/config/views.view.aggregator_rss_feed.yml b/core/modules/aggregator/config/views.view.aggregator_rss_feed.yml index 2590960..dfefa21 100644 --- a/core/modules/aggregator/config/views.view.aggregator_rss_feed.yml +++ b/core/modules/aggregator/config/views.view.aggregator_rss_feed.yml @@ -140,5 +140,4 @@ label: 'Aggregator RSS feed' module: views id: aggregator_rss_feed tag: aggregator -uuid: 7dfa5cb7-2248-4d52-8c00-cd8e02d1e78e langcode: en diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php index 1918bbc..3ade60e 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php @@ -16,7 +16,7 @@ /** * Defines the aggregator feed entity class. * - * @EntityType( + * @ContentEntityType( * id = "aggregator_feed", * label = @Translation("Aggregator feed"), * controllers = { diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php index 9b88830..191f5bc 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php @@ -15,7 +15,7 @@ /** * Defines the aggregator item entity class. * - * @EntityType( + * @ContentEntityType( * id = "aggregator_item", * label = @Translation("Aggregator feed item"), * controllers = { diff --git a/core/modules/aggregator/tests/modules/aggregator_test_views/test_views/views.view.test_aggregator_items.yml b/core/modules/aggregator/tests/modules/aggregator_test_views/test_views/views.view.test_aggregator_items.yml index 0d6dcbb..cb9e7ae 100644 --- a/core/modules/aggregator/tests/modules/aggregator_test_views/test_views/views.view.test_aggregator_items.yml +++ b/core/modules/aggregator/tests/modules/aggregator_test_views/test_views/views.view.test_aggregator_items.yml @@ -166,4 +166,3 @@ module: views id: test_aggregator_items tag: '' langcode: en -uuid: 19dd643f-9324-44df-ac72-0be915b334d1 diff --git a/core/modules/ban/lib/Drupal/ban/EventSubscriber/BanSubscriber.php b/core/modules/ban/lib/Drupal/ban/EventSubscriber/BanSubscriber.php index 6807cce..47035ee 100644 --- a/core/modules/ban/lib/Drupal/ban/EventSubscriber/BanSubscriber.php +++ b/core/modules/ban/lib/Drupal/ban/EventSubscriber/BanSubscriber.php @@ -13,6 +13,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\ban\BanIpManager; +use Drupal\Component\Utility\String; /** * Ban subscriber for controller requests. @@ -45,7 +46,7 @@ public function __construct(BanIpManager $manager) { public function onKernelRequestBannedIpCheck(GetResponseEvent $event) { $ip = $event->getRequest()->getClientIp(); if ($this->manager->isDenied($ip)) { - $response = new Response('Sorry, ' . check_plain($ip) . ' has been banned.', 403); + $response = new Response('Sorry, ' . String::checkPlain($ip) . ' has been banned.', 403); $event->setResponse($response); } } diff --git a/core/modules/block/block.api.php b/core/modules/block/block.api.php index c6add64..065a1cd 100644 --- a/core/modules/block/block.api.php +++ b/core/modules/block/block.api.php @@ -20,7 +20,7 @@ * If the module wishes to act on the rendered HTML of the block rather than * the structured content array, it may use this hook to add a #post_render * callback. Alternatively, it could also implement hook_preprocess_HOOK() for - * block.html.twig. See drupal_render() and theme() documentation respectively + * block.html.twig. See drupal_render() and _theme() documentation respectively * for details. * * In addition to hook_block_view_alter(), which is called for all blocks, there diff --git a/core/modules/block/block.local_tasks.yml b/core/modules/block/block.local_tasks.yml index 3d770ed..ca6917b 100644 --- a/core/modules/block/block.local_tasks.yml +++ b/core/modules/block/block.local_tasks.yml @@ -5,11 +5,11 @@ block.admin_edit: # Per theme block layout pages. block.admin_display: - title: 'Block Layout' + title: 'Block layout' route_name: block.admin_display base_route: block.admin_display block.admin_display_theme: - title: 'Block Layout' + title: 'Block layout' route_name: block.admin_display_theme parent_id: block.admin_display derivative: 'Drupal\block\Plugin\Derivative\ThemeLocalTask' diff --git a/core/modules/block/custom_block/config/custom_block.type.basic.yml b/core/modules/block/custom_block/config/custom_block.type.basic.yml index e9cd395..02982e4 100644 --- a/core/modules/block/custom_block/config/custom_block.type.basic.yml +++ b/core/modules/block/custom_block/config/custom_block.type.basic.yml @@ -1,6 +1,5 @@ id: basic label: 'Basic block' -uuid: 4bcdec7a-c867-404b-855d-939a11420b12 revision: 0 description: 'A basic block contains a title and a body.' langcode: en diff --git a/core/modules/block/custom_block/config/entity.view_mode.custom_block.full.yml b/core/modules/block/custom_block/config/entity.view_mode.custom_block.full.yml index b0518cb..ba11a62 100644 --- a/core/modules/block/custom_block/config/entity.view_mode.custom_block.full.yml +++ b/core/modules/block/custom_block/config/entity.view_mode.custom_block.full.yml @@ -1,5 +1,4 @@ id: custom_block.full -uuid: 96f20030-6465-43ed-9e00-f2a16f52ef6e label: Full status: false cache: true diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index cdf90c7..0d16abf 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -136,15 +136,15 @@ function custom_block_load($id) { } /** - * Implements hook_entity_info_alter(). + * Implements hook_entity_type_alter(). */ -function custom_block_entity_info_alter(&$entity_info) { - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ +function custom_block_entity_type_alter(array &$entity_types) { + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ // Add a translation handler for fields if the language module is enabled. if (\Drupal::moduleHandler()->moduleExists('language')) { - $translation = $entity_info['custom_block']->get('translation'); + $translation = $entity_types['custom_block']->get('translation'); $translation['custom_block'] = TRUE; - $entity_info['custom_block']->set('translation', $translation); + $entity_types['custom_block']->set('translation', $translation); } } @@ -176,7 +176,7 @@ function custom_block_add_body_field($block_type_id, $label = 'Block body') { $field = field_info_field('custom_block', 'body'); $instance = field_info_instance('custom_block', 'body', $block_type_id); if (empty($field)) { - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'body', 'entity_type' => 'custom_block', 'type' => 'text_with_summary', @@ -184,7 +184,7 @@ function custom_block_add_body_field($block_type_id, $label = 'Block body') { $field->save(); } if (empty($instance)) { - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'body', 'entity_type' => 'custom_block', 'bundle' => $block_type_id, diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php index 68c3b10..c2b0325 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php @@ -15,12 +15,11 @@ /** * Defines the custom block entity class. * - * @EntityType( + * @ContentEntityType( * id = "custom_block", * label = @Translation("Custom Block"), * bundle_label = @Translation("Custom Block type"), * controllers = { - * "storage" = "Drupal\Core\Entity\FieldableDatabaseStorageController", * "access" = "Drupal\custom_block\CustomBlockAccessController", * "list" = "Drupal\custom_block\CustomBlockListController", * "view_builder" = "Drupal\custom_block\CustomBlockViewBuilder", @@ -188,9 +187,10 @@ public static function baseFieldDefinitions($entity_type) { ->setLabel(t('Subject')) ->setDescription(t('The custom block name.')); - $fields['type'] = FieldDefinition::create('string') + $fields['type'] = FieldDefinition::create('entity_reference') ->setLabel(t('Block type')) - ->setDescription(t('The block type.')); + ->setDescription(t('The block type.')) + ->setSetting('target_type', 'custom_block_type'); $fields['log'] = FieldDefinition::create('string') ->setLabel(t('Revision log message')) diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php index 0b41a4d..d630254 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php @@ -14,11 +14,10 @@ /** * Defines the custom block type entity. * - * @EntityType( + * @ConfigEntityType( * id = "custom_block_type", * label = @Translation("Custom block type"), * controllers = { - * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController", * "form" = { * "default" = "Drupal\custom_block\CustomBlockTypeFormController", * "add" = "Drupal\custom_block\CustomBlockTypeFormController", diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php index 57f1e99..ffa7191 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php @@ -25,14 +25,14 @@ class CustomBlockFieldTest extends CustomBlockTestBase { /** * The created field. * - * @var \Drupal\field\Entity\Field + * @var \Drupal\field\Entity\FieldConfig */ protected $field; /** * The created instance. * - * @var \Drupal\field\Entity\FieldInstance + * @var \Drupal\field\Entity\FieldInstanceConfig */ protected $instance; @@ -64,14 +64,14 @@ public function testBlockFields() { $this->blockType = $this->createCustomBlockType('link'); // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'custom_block', 'type' => 'link', 'cardinality' => 2, )); $this->field->save(); - $this->instance = entity_create('field_instance', array( + $this->instance = entity_create('field_instance_config', array( 'field_name' => $this->field->getName(), 'entity_type' => 'custom_block', 'bundle' => 'link', diff --git a/core/modules/block/lib/Drupal/block/BlockListController.php b/core/modules/block/lib/Drupal/block/BlockListController.php index 81a3800..f66883c 100644 --- a/core/modules/block/lib/Drupal/block/BlockListController.php +++ b/core/modules/block/lib/Drupal/block/BlockListController.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Utility\Json; use Drupal\Component\Utility\String; +use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Entity\ConfigEntityListController; use Drupal\Core\Entity\EntityControllerInterface; use Drupal\Core\Entity\EntityInterface; @@ -412,7 +413,7 @@ public function submitForm(array &$form, array &$form_state) { $entity->save(); } drupal_set_message(t('The block settings have been updated.')); - cache_invalidate_tags(array('content' => TRUE)); + Cache::invalidateTags(array('content' => TRUE)); } } diff --git a/core/modules/block/lib/Drupal/block/BlockViewBuilder.php b/core/modules/block/lib/Drupal/block/BlockViewBuilder.php index 200b428..a076dc9 100644 --- a/core/modules/block/lib/Drupal/block/BlockViewBuilder.php +++ b/core/modules/block/lib/Drupal/block/BlockViewBuilder.php @@ -7,6 +7,7 @@ namespace Drupal\block; +use Drupal\Component\Utility\String; use Drupal\Core\Entity\EntityViewBuilder; use Drupal\Core\Entity\EntityViewBuilderInterface; use Drupal\Core\Entity\EntityInterface; @@ -61,7 +62,7 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la '#base_plugin_id' => $base_id, '#derivative_plugin_id' => $derivative_id, ); - $build[$key]['#configuration']['label'] = check_plain($configuration['label']); + $build[$key]['#configuration']['label'] = String::checkPlain($configuration['label']); // Place the $content returned by the block plugin into a 'content' // child element, as a way to allow the plugin to have complete control diff --git a/core/modules/block/lib/Drupal/block/Entity/Block.php b/core/modules/block/lib/Drupal/block/Entity/Block.php index dc20929..9437e77 100644 --- a/core/modules/block/lib/Drupal/block/Entity/Block.php +++ b/core/modules/block/lib/Drupal/block/Entity/Block.php @@ -15,11 +15,10 @@ /** * Defines a Block configuration entity class. * - * @EntityType( + * @ConfigEntityType( * id = "block", * label = @Translation("Block"), * controllers = { - * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController", * "access" = "Drupal\block\BlockAccessController", * "view_builder" = "Drupal\block\BlockViewBuilder", * "list" = "Drupal\block\BlockListController", diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php index 6206dbb..7414efd 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php @@ -7,6 +7,7 @@ namespace Drupal\block\Tests; +use Drupal\Core\Cache\Cache; use Drupal\simpletest\WebTestBase; /** @@ -80,7 +81,7 @@ function testCachePerRole() { $this->assertText($old_content, 'Block is served from the cache.'); // Clear the cache and verify that the stale data is no longer there. - cache_invalidate_tags(array('content' => TRUE)); + Cache::invalidateTags(array('content' => TRUE)); $this->drupalGet(''); $this->assertNoText($old_content, 'Block cache clear removes stale cache data.'); $this->assertText($current_content, 'Fresh block content is displayed after clearing the cache.'); diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 1b6f4ea..acfa539 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -5,6 +5,7 @@ * Allows users to create and organize related content in an outline. */ +use Drupal\Component\Utility\String; use Drupal\Core\Entity\EntityInterface; use Drupal\node\NodeInterface; use Drupal\node\NodeTypeInterface; @@ -112,11 +113,11 @@ function book_permission() { } /** - * Implements hook_entity_info(). + * Implements hook_entity_type_build(). */ -function book_entity_info(&$entity_info) { - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ - $entity_info['node'] +function book_entity_type_build(array &$entity_types) { + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ + $entity_types['node'] ->setFormClass('book_outline', 'Drupal\book\Form\BookOutlineForm') ->setLinkTemplate('book-outline-form', 'book.outline') ->setLinkTemplate('book-remove-form', 'book.remove'); @@ -661,7 +662,7 @@ function template_preprocess_book_navigation(&$variables) { // Provide extra variables for themers. Not needed by default. $variables['book_id'] = $book_link['bid']; - $variables['book_title'] = check_plain($book_link['link_title']); + $variables['book_title'] = String::checkPlain($book_link['link_title']); $variables['book_url'] = 'node/' . $book_link['bid']; $variables['current_depth'] = $book_link['depth']; $variables['tree'] = ''; @@ -678,7 +679,7 @@ function template_preprocess_book_navigation(&$variables) { 'href' => $prev_href, ); $variables['prev_url'] = $prev_href; - $variables['prev_title'] = check_plain($prev['title']); + $variables['prev_title'] = String::checkPlain($prev['title']); } if ($book_link['plid'] && $parent = book_link_load($book_link['plid'])) { @@ -688,7 +689,7 @@ function template_preprocess_book_navigation(&$variables) { 'href' => $parent_href, ); $variables['parent_url'] = $parent_href; - $variables['parent_title'] = check_plain($parent['title']); + $variables['parent_title'] = String::checkPlain($parent['title']); } if ($next = book_next($book_link)) { @@ -698,7 +699,7 @@ function template_preprocess_book_navigation(&$variables) { 'href' => $next_href, ); $variables['next_url'] = $next_href; - $variables['next_title'] = check_plain($next['title']); + $variables['next_title'] = String::checkPlain($next['title']); } } @@ -736,7 +737,7 @@ function template_preprocess_book_export_html(&$variables) { global $base_url; $language_interface = language(Language::TYPE_INTERFACE); - $variables['title'] = check_plain($variables['title']); + $variables['title'] = String::checkPlain($variables['title']); $variables['base_url'] = $base_url; $variables['language'] = $language_interface; $variables['language_rtl'] = ($language_interface->direction == Language::DIRECTION_RTL); @@ -762,7 +763,7 @@ function template_preprocess_book_export_html(&$variables) { */ function template_preprocess_book_node_export_html(&$variables) { $variables['depth'] = $variables['node']->book['depth']; - $variables['title'] = check_plain($variables['node']->label()); + $variables['title'] = String::checkPlain($variables['node']->label()); $variables['content'] = $variables['node']->rendered; } diff --git a/core/modules/book/config/entity.view_mode.node.print.yml b/core/modules/book/config/entity.view_mode.node.print.yml index 88eea2e..7854ec1 100644 --- a/core/modules/book/config/entity.view_mode.node.print.yml +++ b/core/modules/book/config/entity.view_mode.node.print.yml @@ -1,5 +1,4 @@ id: node.print -uuid: 58ded254-7114-4e5b-a50d-1351c48807d8 label: Print status: false cache: true diff --git a/core/modules/book/config/node.type.book.yml b/core/modules/book/config/node.type.book.yml index e8ee747..e7ad5f7 100644 --- a/core/modules/book/config/node.type.book.yml +++ b/core/modules/book/config/node.type.book.yml @@ -1,5 +1,4 @@ type: book -uuid: c5ca890d-7db7-4c45-bf0f-0a12430923ff name: 'Book page' description: 'Books have a built-in hierarchical navigation. Use for handbooks or tutorials.' help: '' diff --git a/core/modules/book/lib/Drupal/book/BookManager.php b/core/modules/book/lib/Drupal/book/BookManager.php index 37982ff..077dab7 100644 --- a/core/modules/book/lib/Drupal/book/BookManager.php +++ b/core/modules/book/lib/Drupal/book/BookManager.php @@ -562,7 +562,7 @@ public function bookTreeAllData($menu_name, $link = NULL, $max_depth = NULL) { if (!isset($tree[$cid])) { // If the static variable doesn't have the data, check {cache_menu}. - $cache = cache('menu')->get($cid); + $cache = \Drupal::cache('menu')->get($cid); if ($cache && isset($cache->data)) { // If the cache entry exists, it contains the parameters for // menu_build_tree(). @@ -589,7 +589,7 @@ public function bookTreeAllData($menu_name, $link = NULL, $max_depth = NULL) { } // Cache the tree building parameters using the page-specific cid. - cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name)); + \Drupal::cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name)); } // Build the tree using the parameters; the resulting tree will be cached @@ -733,7 +733,7 @@ protected function _menu_build_tree($menu_name, array $parameters = array()) { // If we do not have this tree in the static cache, check {cache_menu}. if (!isset($trees[$tree_cid])) { - $cache = cache('menu')->get($tree_cid); + $cache = \Drupal::cache('menu')->get($tree_cid); if ($cache && isset($cache->data)) { $trees[$tree_cid] = $cache->data; } @@ -776,7 +776,7 @@ protected function _menu_build_tree($menu_name, array $parameters = array()) { $this->bookTreeCollectNodeLinks($data['tree'], $data['node_links']); // Cache the data, if it is not already in the cache. - cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name)); + \Drupal::cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name)); $trees[$tree_cid] = $data; } @@ -993,12 +993,12 @@ public function bookMenuSubtreeData($link) { $cid = 'links:' . $link['menu_name'] . ':subtree-cid:' . $link['mlid']; if (!isset($tree[$cid])) { - $cache = cache('menu')->get($cid); + $cache = \Drupal::cache('menu')->get($cid); if ($cache && isset($cache->data)) { // If the cache entry exists, it will just be the cid for the actual data. // This avoids duplication of large amounts of data. - $cache = cache('menu')->get($cache->data); + $cache = \Drupal::cache('menu')->get($cache->data); if ($cache && isset($cache->data)) { $data = $cache->data; @@ -1029,11 +1029,11 @@ public function bookMenuSubtreeData($link) { $tree_cid = 'links:' . $item['menu_name'] . ':subtree-data:' . hash('sha256', serialize($data)); // Cache the data, if it is not already in the cache. - if (!cache('menu')->get($tree_cid)) { - cache('menu')->set($tree_cid, $data); + if (!\Drupal::cache('menu')->get($tree_cid)) { + \Drupal::cache('menu')->set($tree_cid, $data); } // Cache the cid of the (shared) data using the menu and item-specific cid. - cache('menu')->set($cid, $tree_cid); + \Drupal::cache('menu')->set($cid, $tree_cid); } // Check access for the current user to each item in the tree. $this->bookTreeCheckAccess($data['tree'], $data['node_links']); diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php index b23f6f6..1d40959 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php @@ -18,12 +18,9 @@ /** * Defines the Breakpoint entity. * - * @EntityType( + * @ConfigEntityType( * id = "breakpoint", * label = @Translation("Breakpoint"), - * controllers = { - * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController" - * }, * config_prefix = "breakpoint.breakpoint", * entity_keys = { * "id" = "id", diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php index f038cb1..2833b67 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php @@ -15,12 +15,9 @@ /** * Defines the BreakpointGroup entity. * - * @EntityType( + * @ConfigEntityType( * id = "breakpoint_group", * label = @Translation("Breakpoint group"), - * controllers = { - * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController" - * }, * config_prefix = "breakpoint.breakpoint_group", * entity_keys = { * "id" = "id", diff --git a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.mobile.yml b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.mobile.yml index 3f30595..8e5e3c4 100644 --- a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.mobile.yml +++ b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.mobile.yml @@ -1,5 +1,4 @@ id: theme.breakpoint_test_theme.mobile -uuid: 3ae8bfe6-496b-478c-a811-17424038f49c name: mobile label: mobile mediaQuery: '(min-width: 0px)' diff --git a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.narrow.yml b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.narrow.yml index e0773e3..a34b582 100644 --- a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.narrow.yml +++ b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.narrow.yml @@ -1,5 +1,4 @@ id: theme.breakpoint_test_theme.narrow -uuid: 1d791b4a-7ccf-4c93-a800-c2bc2594cc62 name: narrow label: narrow mediaQuery: '(min-width: 560px)' diff --git a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.tv.yml b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.tv.yml index 9f4d189..d594ff4 100644 --- a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.tv.yml +++ b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.tv.yml @@ -1,5 +1,4 @@ id: theme.breakpoint_test_theme.tv -uuid: e0ffa737-0570-4891-9809-9bce925673ca name: tv label: tv mediaQuery: 'only screen and (min-width: 3456px)' diff --git a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.wide.yml b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.wide.yml index 112a8e6..34e5f4f 100644 --- a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.wide.yml +++ b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint.theme.breakpoint_test_theme.wide.yml @@ -1,5 +1,4 @@ id: theme.breakpoint_test_theme.wide -uuid: 1561574d-99f8-48a6-b304-4e2b617673b2 name: wide label: wide mediaQuery: '(min-width: 851px)' diff --git a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint_group.theme.breakpoint_test_theme.breakpoint_test_theme.yml b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint_group.theme.breakpoint_test_theme.breakpoint_test_theme.yml index 62ac756..c335fb0 100644 --- a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint_group.theme.breakpoint_test_theme.breakpoint_test_theme.yml +++ b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint_group.theme.breakpoint_test_theme.breakpoint_test_theme.yml @@ -1,5 +1,4 @@ id: theme.breakpoint_test_theme.breakpoint_test_theme -uuid: 94b96e6e-a032-4b29-8100-efd5bf854fd1 name: breakpoint_test_theme label: 'Breakpoint test theme' breakpoint_ids: diff --git a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint_group.theme.breakpoint_test_theme.test.yml b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint_group.theme.breakpoint_test_theme.test.yml index e185e7f..e074998 100644 --- a/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint_group.theme.breakpoint_test_theme.test.yml +++ b/core/modules/breakpoint/tests/themes/breakpoint_test_theme/config/breakpoint.breakpoint_group.theme.breakpoint_test_theme.test.yml @@ -1,5 +1,4 @@ id: theme.breakpoint_test_theme.test -uuid: fcc25180-7e18-4149-8962-98d706faa59a name: test label: 'Test Theme' breakpoint_ids: diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php index 21db722..3b5e6cb 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php @@ -313,7 +313,7 @@ public function getLangcodes() { // be expensive to calculate all the time. The cache is cleared on core // upgrades which is the only situation the CKEditor file listing should // change. - $langcode_cache = cache('ckeditor.languages')->get('langcodes'); + $langcode_cache = \Drupal::cache('ckeditor.languages')->get('langcodes'); if (!empty($langcode_cache)) { $langcodes = $langcode_cache->data; } @@ -325,7 +325,7 @@ public function getLangcodes() { $langcode = $language_file->getBasename('.js'); $langcodes[$langcode] = $langcode; } - cache('ckeditor.languages')->set('langcodes', $langcodes); + \Drupal::cache('ckeditor.languages')->set('langcodes', $langcodes); } // Get language mapping if available to map to Drupal language codes. diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 72491d6..249f6f1 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -5,6 +5,7 @@ */ use Drupal\Core\Asset\CssOptimizer; +use Drupal\Component\Utility\String; /** * Implements hook_help(). @@ -214,7 +215,7 @@ function color_scheme_form($complete_form, &$form_state, $theme) { if (isset($names[$name])) { $form['palette'][$name] = array( '#type' => 'textfield', - '#title' => check_plain($names[$name]), + '#title' => String::checkPlain($names[$name]), '#value_callback' => 'color_palette_color_value', '#default_value' => $value, '#size' => 8, diff --git a/core/modules/comment/comment.api.php b/core/modules/comment/comment.api.php index 0004793..00b8efc 100644 --- a/core/modules/comment/comment.api.php +++ b/core/modules/comment/comment.api.php @@ -24,7 +24,7 @@ */ function hook_comment_presave(Drupal\comment\Comment $comment) { // Remove leading & trailing spaces from the comment subject. - $comment->subject->value = trim($comment->subject->value); + $comment->setSubject(trim($comment->getSubject())); } /** @@ -35,8 +35,8 @@ function hook_comment_presave(Drupal\comment\Comment $comment) { */ function hook_comment_insert(Drupal\comment\Comment $comment) { // Reindex the node when comments are added. - if ($comment->entity_type->value == 'node') { - node_reindex_node_search($comment->entity_id->value); + if ($comment->getCommentedEntityTypeId() == 'node') { + node_reindex_node_search($comment->getCommentedEntityId()); } } @@ -48,8 +48,8 @@ function hook_comment_insert(Drupal\comment\Comment $comment) { */ function hook_comment_update(Drupal\comment\Comment $comment) { // Reindex the node when comments are updated. - if ($comment->entity_type->value == 'node') { - node_reindex_node_search($comment->entity_id->value); + if ($comment->getCommentedEntityTypeId() == 'node') { + node_reindex_node_search($comment->getCommentedEntityId()); } } @@ -149,7 +149,7 @@ function hook_comment_view_alter(&$build, \Drupal\comment\Entity\Comment $commen * The comment the action is being performed on. */ function hook_comment_publish(Drupal\comment\Comment $comment) { - drupal_set_message(t('Comment: @subject has been published', array('@subject' => $comment->subject->value))); + drupal_set_message(t('Comment: @subject has been published', array('@subject' => $comment->getSubject()))); } /** @@ -159,7 +159,7 @@ function hook_comment_publish(Drupal\comment\Comment $comment) { * The comment the action is being performed on. */ function hook_comment_unpublish(Drupal\comment\Comment $comment) { - drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->subject->value))); + drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->getSubject()))); } /** @@ -194,7 +194,7 @@ function hook_comment_predelete(Drupal\comment\Comment $comment) { * @see entity_delete_multiple() */ function hook_comment_delete(Drupal\comment\Comment $comment) { - drupal_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->subject->value))); + drupal_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->getSubject()))); } /** diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 356065f..de9c0c8 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -5,16 +5,12 @@ * Install, update and uninstall functions for the Comment module. */ -use Drupal\Core\Language\Language; -use Drupal\comment\Plugin\Field\FieldType\CommentItem; -use Drupal\field\Entity\Field; - /** * Implements hook_uninstall(). */ function comment_uninstall() { // Remove the comment fields. - $fields = entity_load_multiple_by_properties('field_entity', array('type' => 'comment')); + $fields = entity_load_multiple_by_properties('field_config', array('type' => 'comment')); foreach ($fields as $field) { entity_invoke_bundle_hook('delete', 'comment', $field->entity_type . '__' . $field->name); $field->delete(); diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 26602ef..fe0c572 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -236,9 +236,9 @@ function comment_count_unpublished() { } /** - * Implements hook_ENTITY_TYPE_insert() for 'field_instance'. + * Implements hook_ENTITY_TYPE_insert() for 'field_instance_config'. */ -function comment_field_instance_insert(FieldInstanceInterface $instance) { +function comment_field_instance_config_insert(FieldInstanceInterface $instance) { if ($instance->getType() == 'comment' && !$instance->isSyncing()) { \Drupal::service('comment.manager')->addBodyField($instance->entity_type, $instance->getName()); \Drupal::cache()->delete('comment_entity_info'); @@ -246,9 +246,9 @@ function comment_field_instance_insert(FieldInstanceInterface $instance) { } /** - * Implements hook_ENTITY_TYPE_create() for 'field_instance'. + * Implements hook_ENTITY_TYPE_create() for 'field_instance_config'. */ -function comment_field_instance_create(FieldInstanceInterface $instance) { +function comment_field_instance_config_create(FieldInstanceInterface $instance) { if ($instance->getType() == 'comment' && !$instance->isSyncing()) { // Assign default values for the field instance. if (!isset($instance->default_value)) { @@ -267,9 +267,9 @@ function comment_field_instance_create(FieldInstanceInterface $instance) { } /** - * Implements hook_ENTITY_TYPE_update() for 'field_instance'. + * Implements hook_ENTITY_TYPE_update() for 'field_instance_config'. */ -function comment_field_instance_update(FieldInstanceInterface $instance) { +function comment_field_instance_config_update(FieldInstanceInterface $instance) { if ($instance->getType() == 'comment') { \Drupal::entityManager()->getViewBuilder($instance->entity_type)->resetCache(); // Comment field settings also affects the rendering of *comment* entities, @@ -279,9 +279,9 @@ function comment_field_instance_update(FieldInstanceInterface $instance) { } /** - * Implements hook_ENTITY_TYPE_delete() for 'field_entity'. + * Implements hook_ENTITY_TYPE_delete() for 'field_config'. */ -function comment_field_entity_delete(FieldInterface $field) { +function comment_field_config_delete(FieldInterface $field) { if ($field->getType() == 'comment') { // Delete all fields and displays attached to the comment bundle. entity_invoke_bundle_hook('delete', 'comment', $field->getName()); @@ -290,9 +290,9 @@ function comment_field_entity_delete(FieldInterface $field) { } /** - * Implements hook_ENTITY_TYPE_delete() for 'field_instance'. + * Implements hook_ENTITY_TYPE_delete() for 'field_instance_config'. */ -function comment_field_instance_delete(FieldInstanceInterface $instance) { +function comment_field_instance_config_delete(FieldInstanceInterface $instance) { if ($instance->getType() == 'comment') { // Delete all comments that used by the entity bundle. $comments = db_query("SELECT cid FROM {comment} WHERE entity_type = :entity_type AND field_id = :field_id", array( @@ -749,7 +749,7 @@ function comment_prepare_thread(&$comments) { foreach ($comments as $key => &$comment) { // The $divs element instructs #prefix whether to add an indent div or // close existing divs (a negative value). - $comment->depth = count(explode('.', $comment->thread->value)) - 1; + $comment->depth = count(explode('.', $comment->getThread())) - 1; if ($comment->depth > $divs) { $comment->divs = 1; $divs++; @@ -935,7 +935,7 @@ function comment_entity_insert(EntityInterface $entity) { 'last_comment_timestamp', 'last_comment_name', 'last_comment_uid', - 'comment_count' + 'comment_count', )); $execute_query = FALSE; foreach ($fields as $field_name => $detail) { @@ -1094,7 +1094,7 @@ function comment_user_cancel($edit, $account, $method) { case 'user_cancel_block_unpublish': $comments = entity_load_multiple_by_properties('comment', array('uid' => $account->id())); foreach ($comments as $comment) { - $comment->status->value = 0; + $comment->setPublished(COMMENT_NOT_PUBLISHED); $comment->save(); } break; @@ -1121,7 +1121,8 @@ function comment_user_predelete($account) { /** * Loads comment entities from the database. * - * @deprecated Use entity_load_multiple('comment', $cids) instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use entity_load_multiple('comment', $cids). * * @param array $cids * (optional) An array of entity IDs. If omitted, all entities are loaded. @@ -1285,12 +1286,13 @@ function comment_get_display_page($cid, $instance) { */ function comment_preview(CommentInterface $comment, array &$form_state) { $preview_build = array(); - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + $entity = $comment->getCommentedEntity(); if (!form_get_errors($form_state)) { // Attach the user and time information. - if (!empty($comment->name->value)) { - $account = user_load_by_name($comment->name->value); + $author_name = $comment->getAuthorName(); + if (!empty($author_name)) { + $account = user_load_by_name($author_name); } elseif (\Drupal::currentUser()->isAuthenticated() && empty($comment->is_anonymous)) { $account = \Drupal::currentUser(); @@ -1298,13 +1300,14 @@ function comment_preview(CommentInterface $comment, array &$form_state) { if (!empty($account) && $account->isAuthenticated()) { $comment->setOwner($account); - $comment->name->value = check_plain($account->getUsername()); + $comment->setAuthorName(check_plain($account->getUsername())); } - else { - $comment->name->value = \Drupal::config('user.settings')->get('anonymous'); + elseif (empty($author_name)) { + $comment->setAuthorName(\Drupal::config('user.settings')->get('anonymous')); } - $comment->created->value = !empty($comment->created->value) ? $comment->created->value : REQUEST_TIME; + $created_time = !is_null($comment->getCreatedTime()) ? $comment->getCreatedTime() : REQUEST_TIME; + $comment->setCreatedTime($created_time); $comment->changed->value = REQUEST_TIME; $comment->in_preview = TRUE; $comment_build = comment_view($comment); @@ -1313,10 +1316,10 @@ function comment_preview(CommentInterface $comment, array &$form_state) { $preview_build['comment_preview'] = $comment_build; } - if ($comment->pid->target_id) { + if ($comment->hasParentComment()) { $build = array(); - $parent = $comment->pid->entity; - if ($parent && $parent->status->value == CommentInterface::PUBLISHED) { + $parent = $comment->getParentComment(); + if ($parent && $parent->isPublished()) { $build = comment_view($parent); } } @@ -1332,7 +1335,7 @@ function comment_preview(CommentInterface $comment, array &$form_state) { // entity is rendered, it excludes the comment field output. As objects are // always addressed by reference we ensure changes are not lost by setting // the value back to its original state after the call to entity_view(). - $field_name = $comment->field_name->value; + $field_name = $comment->getFieldName(); $original_value = $entity->get($field_name); $entity->set($field_name, COMMENT_HIDDEN); $build = entity_view($entity, 'full'); @@ -1370,7 +1373,7 @@ function comment_prepare_author(CommentInterface $comment) { // The account has been pre-loaded by CommentViewBuilder::buildContent(). $account = $comment->getOwner(); if (empty($account->uid->value)) { - $account = entity_create('user', array('uid' => 0, 'name' => $comment->name->value, 'homepage' => $comment->homepage->value)); + $account = entity_create('user', array('uid' => 0, 'name' => $comment->getAuthorName(), 'homepage' => $comment->getHomepage())); } return $account; } @@ -1388,25 +1391,24 @@ function comment_prepare_author(CommentInterface $comment) { function template_preprocess_comment(&$variables) { /** @var \Drupal\comment\CommentInterface $comment */ $comment = $variables['elements']['#comment']; - $commented_entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + $commented_entity = $comment->getCommentedEntity(); $variables['comment'] = $comment; $variables['commented_entity'] = $commented_entity; $account = comment_prepare_author($comment); - // @todo Do not call theme() here. We do this for purposes of t(). $username = array( '#theme' => 'username', '#account' => $account, ); $variables['author'] = drupal_render($username); - $variables['new_indicator_timestamp'] = $comment->changed->value; - $variables['created'] = format_date($comment->created->value); + $variables['new_indicator_timestamp'] = $comment->getChangedTime(); + $variables['created'] = format_date($comment->getCreatedTime()); // Avoid calling format_date() twice on the same timestamp. - if ($comment->changed->value == $comment->created->value) { + if ($comment->getChangedTime() == $comment->getCreatedTime()) { $variables['changed'] = $variables['created']; } else { - $variables['changed'] = format_date($comment->changed->value); + $variables['changed'] = format_date($comment->getChangedTime()); } if (theme_get_setting('features.comment_user_picture')) { @@ -1425,13 +1427,13 @@ function template_preprocess_comment(&$variables) { $variables['signature'] = ''; } if (isset($comment->in_preview)) { - $variables['title'] = l($comment->subject->value, ''); + $variables['title'] = l($comment->getSubject(), ''); $variables['permalink'] = l(t('Permalink'), ''); } else { $uri = $comment->urlInfo(); $uri['options'] += array('attributes' => array('class' => array('permalink'), 'rel' => 'bookmark')); - $variables['title'] = \Drupal::l($comment->subject->value, $uri['route_name'], $uri['route_parameters'], $uri['options']); + $variables['title'] = \Drupal::l($comment->getSubject(), $uri['route_name'], $uri['route_parameters'], $uri['options']); $permalink_uri = $comment->permalink(); $variables['permalink'] = \Drupal::l(t('Permalink'), $permalink_uri['route_name'], $permalink_uri['route_parameters'], $permalink_uri['options']); @@ -1439,28 +1441,27 @@ function template_preprocess_comment(&$variables) { $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['created'])); - if ($comment->pid->target_id) { + if ($comment->hasParentComment()) { // Fetch and store the parent comment information for use in templates. - $comment_parent = $comment->pid->entity; + $comment_parent = $comment->getParentComment(); $account_parent = comment_prepare_author($comment_parent); $variables['parent_comment'] = $comment_parent; - // @todo Do not call theme() here. We do this for purposes of t(). $username = array( '#theme' => 'username', '#account' => $account_parent, ); $variables['parent_author'] = drupal_render($username); - $variables['parent_created'] = format_date($comment_parent->created->value); + $variables['parent_created'] = format_date($comment_parent->getCreatedTime()); // Avoid calling format_date() twice on the same timestamp. - if ($comment_parent->changed->value == $comment_parent->created->value) { + if ($comment_parent->getChangedTime() == $comment_parent->getCreatedTime()) { $variables['parent_changed'] = $variables['parent_created']; } else { - $variables['parent_changed'] = format_date($comment_parent->changed->value); + $variables['parent_changed'] = format_date($comment_parent->getChangedTime()); } $permalink_uri_parent = $comment_parent->permalink(); $permalink_uri_parent['options'] += array('attributes' => array('class' => array('permalink'), 'rel' => 'bookmark')); - $variables['parent_title'] = \Drupal::l($comment_parent->subject->value, $permalink_uri_parent['route_name'], $permalink_uri_parent['route_parameters'], $permalink_uri_parent['options']); + $variables['parent_title'] = \Drupal::l($comment_parent->getSubject(), $permalink_uri_parent['route_name'], $permalink_uri_parent['route_parameters'], $permalink_uri_parent['options']); $variables['parent_permalink'] = \Drupal::l(t('Parent permalink'), $permalink_uri_parent['route_name'], $permalink_uri_parent['route_parameters'], $permalink_uri_parent['options']); $variables['parent'] = t('In reply to !parent_title by !parent_username', array('!parent_username' => $variables['parent_author'], '!parent_title' => $variables['parent_title'])); @@ -1485,7 +1486,7 @@ function template_preprocess_comment(&$variables) { $variables['status'] = 'preview'; } else { - $variables['status'] = ($comment->status->value == CommentInterface::NOT_PUBLISHED) ? 'unpublished' : 'published'; + $variables['status'] = $comment->isPublished() ? 'published' : 'unpublished'; } // Gather comment classes. @@ -1573,9 +1574,9 @@ function comment_ranking() { * Implements hook_file_download_access(). */ function comment_file_download_access($field, EntityInterface $entity, FileInterface $file) { - if ($entity->getEntityTypeId() == 'comment') { - if (user_access('access comments') && $entity->status->value == CommentInterface::PUBLISHED || user_access('administer comments')) { - $commented_entity = entity_load($entity->entity_type->value, $entity->entity_id->value); + if ($entity instanceof CommentInterface) { + if (user_access('access comments') && $entity->isPublished() || user_access('administer comments')) { + $commented_entity = $entity->getCommentedEntity(); // Check access to parent entity. return $commented_entity->access('view'); } diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc index 91b1eb2..ecff337 100644 --- a/core/modules/comment/comment.tokens.inc +++ b/core/modules/comment/comment.tokens.inc @@ -137,32 +137,27 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = $replacements[$original] = $comment->id(); break; - // Poster identity information for comments + // Poster identity information for comments. case 'hostname': - $replacements[$original] = $sanitize ? check_plain($comment->hostname->value) : $comment->hostname->value; + $replacements[$original] = $sanitize ? check_plain($comment->getHostname()) : $comment->getHostname(); break; case 'name': - $name = ($comment->getOwnerId() == 0) ? \Drupal::config('user.settings')->get('anonymous') : $comment->name->value; + $name = ($comment->getOwnerId() == 0) ? \Drupal::config('user.settings')->get('anonymous') : $comment->getAuthorName(); $replacements[$original] = $sanitize ? filter_xss($name) : $name; break; case 'mail': - if ($comment->getOwnerId()) { - $mail = $comment->getOwner()->getEmail(); - } - else { - $mail = $comment->mail->value; - } + $mail = $comment->getAuthorEmail(); $replacements[$original] = $sanitize ? check_plain($mail) : $mail; break; case 'homepage': - $replacements[$original] = $sanitize ? check_url($comment->homepage->value) : $comment->homepage->value; + $replacements[$original] = $sanitize ? check_url($comment->getHomepage()) : $comment->getHomepage(); break; case 'title': - $replacements[$original] = $sanitize ? filter_xss($comment->subject->value) : $comment->subject->value; + $replacements[$original] = $sanitize ? filter_xss($comment->getSubject()) : $comment->getSubject(); break; case 'body': @@ -180,28 +175,31 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = $replacements[$original] = url('comment/' . $comment->id() . '/edit', $url_options); break; - // Default values for the chained tokens handled below. + // @todo Remove 'name' token in favour of 'author'. See + // https://drupal.org/node/920056. + case 'name': case 'author': - $replacements[$original] = $sanitize ? filter_xss($comment->name->value) : $comment->name->value; + $name = $comment->getAuthorName(); + $replacements[$original] = $sanitize ? filter_xss($name) : $name; break; case 'parent': - if (!empty($comment->pid->target_id)) { - $parent = entity_load('comment', $comment->pid->target_id); - $replacements[$original] = $sanitize ? filter_xss($parent->subject->value) : $parent->subject->value; + if ($comment->hasParentComment()) { + $parent = $comment->getParentComment(); + $replacements[$original] = $sanitize ? filter_xss($parent->getSubject()) : $parent->getSubject(); } break; case 'created': - $replacements[$original] = format_date($comment->created->value, 'medium', '', NULL, $langcode); + $replacements[$original] = format_date($comment->getCreatedTime(), 'medium', '', NULL, $langcode); break; case 'changed': - $replacements[$original] = format_date($comment->changed->value, 'medium', '', NULL, $langcode); + $replacements[$original] = format_date($comment->getChangedTime(), 'medium', '', NULL, $langcode); break; case 'entity': - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + $entity = $comment->getCommentedEntity(); $title = $entity->label(); $replacements[$original] = $sanitize ? filter_xss($title) : $title; break; @@ -210,8 +208,8 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = // Support legacy comment node tokens, since tokes are embedded in // user data and can't be upgraded directly. // @todo Remove in Drupal 9, see https://drupal.org/node/2031901. - if ($comment->entity_type->value == 'node') { - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + if ($comment->getCommentedEntityTypeId() == 'node') { + $entity = $comment->getCommentedEntity(); $title = $entity->label(); $replacements[$original] = $sanitize ? filter_xss($title) : $title; } @@ -224,24 +222,24 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = // Chained token relationships. if ($entity_tokens = $token_service->findwithPrefix($tokens, 'entity')) { - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); - $replacements += $token_service->generate($comment->entity_type->value, $entity_tokens, array($comment->entity_type->value => $entity), $options); + $entity = $comment->getCommentedEntity(); + $replacements += $token_service->generate($comment->getCommentedEntityTypeId(), $entity_tokens, array($comment->getCommentedEntityTypeId() => $entity), $options); } - if (($node_tokens = $token_service->findwithPrefix($tokens, 'node')) && $comment->entity_type->value == 'node') { - $node = entity_load($comment->entity_type->value, $comment->entity_id->value); + if (($node_tokens = $token_service->findwithPrefix($tokens, 'node')) && $comment->getCommentedEntityTypeId() == 'node') { + $node = $comment->getCommentedEntity(); $replacements += $token_service->generate('node', $node_tokens, array('node' => $node), $options); } if ($date_tokens = $token_service->findwithPrefix($tokens, 'created')) { - $replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->created->value), $options); + $replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->getCreatedTime()), $options); } if ($date_tokens = $token_service->findwithPrefix($tokens, 'changed')) { - $replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->changed->value), $options); + $replacements += $token_service->generate('date', $date_tokens, array('date' => $comment->getChangedTime()), $options); } - if (($parent_tokens = $token_service->findwithPrefix($tokens, 'parent')) && $parent = $comment->pid->entity) { + if (($parent_tokens = $token_service->findwithPrefix($tokens, 'parent')) && $parent = $comment->getParentComment()) { $replacements += $token_service->generate('comment', $parent_tokens, array('comment' => $parent), $options); } @@ -255,7 +253,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options = $entity = !empty($data['entity']) ? $data['entity'] : $data['node']; foreach ($tokens as $name => $original) { - switch($name) { + switch ($name) { case 'comment-count': $count = 0; $fields = array_keys(\Drupal::service('comment.manager')->getFields($entity->getEntityTypeId())); diff --git a/core/modules/comment/config/entity.view_mode.comment.full.yml b/core/modules/comment/config/entity.view_mode.comment.full.yml index 9f99609..fd623d4 100644 --- a/core/modules/comment/config/entity.view_mode.comment.full.yml +++ b/core/modules/comment/config/entity.view_mode.comment.full.yml @@ -1,5 +1,4 @@ id: comment.full -uuid: 06ab5b16-e197-4242-b72c-4453793fabba label: 'Full comment' status: false cache: true diff --git a/core/modules/comment/config/system.action.comment_publish_action.yml b/core/modules/comment/config/system.action.comment_publish_action.yml index 5d5e4ee..ae9d93a 100644 --- a/core/modules/comment/config/system.action.comment_publish_action.yml +++ b/core/modules/comment/config/system.action.comment_publish_action.yml @@ -1,5 +1,4 @@ id: comment_publish_action -uuid: 890a554f-f083-400c-8d18-2412f2daa140 label: 'Publish comment' status: true langcode: en diff --git a/core/modules/comment/config/system.action.comment_save_action.yml b/core/modules/comment/config/system.action.comment_save_action.yml index 48c4354..e98a92a 100644 --- a/core/modules/comment/config/system.action.comment_save_action.yml +++ b/core/modules/comment/config/system.action.comment_save_action.yml @@ -1,5 +1,4 @@ id: comment_save_action -uuid: 10a7269e-b454-40d6-8d00-0f9ffed58f74 label: 'Save comment' status: true langcode: en diff --git a/core/modules/comment/config/system.action.comment_unpublish_action.yml b/core/modules/comment/config/system.action.comment_unpublish_action.yml index 3f52583..61b8e24 100644 --- a/core/modules/comment/config/system.action.comment_unpublish_action.yml +++ b/core/modules/comment/config/system.action.comment_unpublish_action.yml @@ -1,5 +1,4 @@ id: comment_unpublish_action -uuid: 64c41e18-26c2-4e54-9747-71018ea27877 label: 'Unpublish comment' status: true langcode: en diff --git a/core/modules/comment/config/views.view.comments_recent.yml b/core/modules/comment/config/views.view.comments_recent.yml index e6559fe..bcc0253 100644 --- a/core/modules/comment/config/views.view.comments_recent.yml +++ b/core/modules/comment/config/views.view.comments_recent.yml @@ -227,4 +227,3 @@ module: views id: comments_recent tag: default langcode: en -uuid: 67212880-6a63-453b-a902-2d13580f7d1c diff --git a/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php b/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php index 276af1e..0190b8d 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php @@ -29,7 +29,7 @@ public function getValue() { // Field id is of the form {entity_type}__{field_name}. We set the // optional limit param to explode() in case the user adds a field with __ // in the name. - $parts = explode('__', $entity->field_id->value, 2); + $parts = explode('__', $entity->getFieldId(), 2); if ($parts && count($parts) == 2) { $this->value = end($parts); } @@ -46,7 +46,7 @@ public function setValue($value, $notify = TRUE) { // Also set the field id. $field = $this->parent->getParent(); $entity = $field->getParent(); - $entity->field_id = $entity->entity_type->value . '__' . $value; + $entity->field_id = $entity->getCommentedEntityTypeId() . '__' . $value; } } diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index b30bc1a..a4312c0 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -86,8 +86,8 @@ protected function init(array &$form_state) { public function form(array $form, array &$form_state) { /** @var \Drupal\comment\CommentInterface $comment */ $comment = $this->entity; - $entity = $this->entityManager->getStorageController($comment->entity_type->value)->load($comment->entity_id->value); - $field_name = $comment->field_name->value; + $entity = $this->entityManager->getStorageController($comment->getCommentedEntityTypeId())->load($comment->getCommentedEntityId()); + $field_name = $comment->getFieldName(); $instance = $this->fieldInfo->getInstance($entity->getEntityTypeId(), $entity->bundle(), $field_name); // Use #comment-form as unique jump target, regardless of entity type. @@ -104,7 +104,7 @@ public function form(array $form, array &$form_state) { // If not replying to a comment, use our dedicated page callback for new // Comments on entities. - if (!$comment->id() && empty($comment->pid->target_id)) { + if (!$comment->id() && !$comment->hasParentComment()) { $form['#action'] = url('comment/reply/' . $entity->getEntityTypeId() . '/' . $entity->id() . '/' . $field_name); } @@ -124,11 +124,11 @@ public function form(array $form, array &$form_state) { // Prepare default values for form elements. if ($is_admin) { - $author = $comment->name->value; - $status = (isset($comment->status->value) ? $comment->status->value : CommentInterface::NOT_PUBLISHED); + $author = $comment->getAuthorName(); + $status = $comment->isPublished(); if (empty($form_state['comment_preview'])) { $form['#title'] = $this->t('Edit comment %title', array( - '%title' => $comment->subject->value, + '%title' => $comment->getSubject(), )); } } @@ -137,14 +137,14 @@ public function form(array $form, array &$form_state) { $author = $this->currentUser->getUsername(); } else { - $author = ($comment->name->value ? $comment->name->value : ''); + $author = ($comment->getAuthorName() ? $comment->getAuthorName() : ''); } $status = ($this->currentUser->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED); } $date = ''; if ($comment->id()) { - $date = !empty($comment->date) ? $comment->date : DrupalDateTime::createFromTimestamp($comment->created->value); + $date = !empty($comment->date) ? $comment->date : DrupalDateTime::createFromTimestamp($comment->getCreatedTime()); } // Add the author name field depending on the current user. @@ -172,7 +172,7 @@ public function form(array $form, array &$form_state) { $form['author']['mail'] = array( '#type' => 'email', '#title' => $this->t('E-mail'), - '#default_value' => $comment->mail->value, + '#default_value' => $comment->getAuthorEmail(), '#required' => ($this->currentUser->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT), '#maxlength' => 64, '#size' => 30, @@ -183,7 +183,7 @@ public function form(array $form, array &$form_state) { $form['author']['homepage'] = array( '#type' => 'url', '#title' => $this->t('Homepage'), - '#default_value' => $comment->homepage->value, + '#default_value' => $comment->getHomepage(), '#maxlength' => 255, '#size' => 30, '#access' => $is_admin || ($this->currentUser->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT), @@ -213,7 +213,7 @@ public function form(array $form, array &$form_state) { '#type' => 'textfield', '#title' => $this->t('Subject'), '#maxlength' => 64, - '#default_value' => $comment->subject->value, + '#default_value' => $comment->getSubject(), '#access' => $instance->getSetting('subject'), ); @@ -238,9 +238,10 @@ public function form(array $form, array &$form_state) { */ protected function actions(array $form, array &$form_state) { $element = parent::actions($form, $form_state); + /* @var \Drupal\comment\CommentInterface $comment */ $comment = $this->entity; - $entity = $this->entityManager->getStorageController($comment->entity_type->value)->load($comment->entity_id->value); - $instance = $this->fieldInfo->getInstance($comment->entity_type->value, $entity->bundle(), $comment->field_name->value); + $entity = $comment->getCommentedEntity(); + $instance = $this->fieldInfo->getInstance($comment->getCommentedEntityTypeId(), $entity->bundle(), $comment->getFieldName()); $preview_mode = $instance->getSetting('preview'); // No delete action on the comment form. @@ -308,10 +309,10 @@ public function validate(array $form, array &$form_state) { public function buildEntity(array $form, array &$form_state) { $comment = parent::buildEntity($form, $form_state); if (!empty($form_state['values']['date']) && $form_state['values']['date'] instanceOf DrupalDateTime) { - $comment->created->value = $form_state['values']['date']->getTimestamp(); + $comment->setCreatedTime($form_state['values']['date']->getTimestamp()); } else { - $comment->created->value = REQUEST_TIME; + $comment->setCreatedTime(REQUEST_TIME); } $comment->changed->value = REQUEST_TIME; return $comment; @@ -327,28 +328,29 @@ public function submit(array $form, array &$form_state) { // If the comment was posted by a registered user, assign the author's ID. // @todo Too fragile. Should be prepared and stored in comment_form() // already. - if (!$comment->is_anonymous && !empty($comment->name->value) && ($account = user_load_by_name($comment->name->value))) { + $author_name = $comment->getAuthorName(); + if (!$comment->is_anonymous && !empty($author_name) && ($account = user_load_by_name($author_name))) { $comment->setOwner($account); } // If the comment was posted by an anonymous user and no author name was // required, use "Anonymous" by default. - if ($comment->is_anonymous && (!isset($comment->name->value) || $comment->name->value === '')) { - $comment->name->value = $this->config('user.settings')->get('anonymous'); + if ($comment->is_anonymous && (!isset($author_name) || $author_name === '')) { + $comment->setAuthorName($this->config('user.settings')->get('anonymous')); } // Validate the comment's subject. If not specified, extract from comment // body. - if (trim($comment->subject->value) == '') { + if (trim($comment->getSubject()) == '') { // The body may be in any format, so: // 1) Filter it into HTML // 2) Strip out all HTML tags // 3) Convert entities back to plain-text. $comment_text = $comment->comment_body->processed; - $comment->subject = Unicode::truncate(trim(String::decodeEntities(strip_tags($comment_text))), 29, TRUE); + $comment->setSubject(Unicode::truncate(trim(String::decodeEntities(strip_tags($comment_text))), 29, TRUE)); // Edge cases where the comment body is populated only by HTML tags will // require a default subject. - if ($comment->subject->value == '') { - $comment->subject->value = $this->t('(No subject)'); + if ($comment->getSubject() == '') { + $comment->setSubject($this->t('(No subject)')); } } @@ -376,7 +378,7 @@ public function preview(array &$form, array &$form_state) { public function save(array $form, array &$form_state) { $entity = entity_load($form_state['values']['entity_type'], $form_state['values']['entity_id']); $comment = $this->entity; - $field_name = $comment->field_name->value; + $field_name = $comment->getFieldName(); $uri = $entity->urlInfo(); if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == COMMENT_OPEN)) { @@ -389,10 +391,10 @@ public function save(array $form, array &$form_state) { $form_state['values']['cid'] = $comment->id(); // Add an entry to the watchdog log. - watchdog('content', 'Comment posted: %subject.', array('%subject' => $comment->subject->value), WATCHDOG_NOTICE, l(t('view'), 'comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id()))); + watchdog('content', 'Comment posted: %subject.', array('%subject' => $comment->getSubject()), WATCHDOG_NOTICE, l(t('view'), 'comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id()))); // Explain the approval queue if necessary. - if ($comment->status->value == CommentInterface::NOT_PUBLISHED) { + if (!$comment->isPublished()) { if (!$this->currentUser->hasPermission('administer comments')) { drupal_set_message($this->t('Your comment has been queued for review by site administrators and will be published after approval.')); } @@ -411,8 +413,8 @@ public function save(array $form, array &$form_state) { $uri['options'] += array('query' => $query, 'fragment' => 'comment-' . $comment->id()); } else { - watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject->value), WATCHDOG_WARNING); - drupal_set_message($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject->value)), 'error'); + watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->getSubject()), WATCHDOG_WARNING); + drupal_set_message($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->getSubject())), 'error'); // Redirect the user to the entity they are commenting on. } $form_state['redirect_route'] = $uri; diff --git a/core/modules/comment/lib/Drupal/comment/CommentInterface.php b/core/modules/comment/lib/Drupal/comment/CommentInterface.php index 0e55501..d42b980 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php @@ -27,6 +27,231 @@ const PUBLISHED = 1; /** + * Determines if this comment is a reply to another comment. + * + * @return bool + * TRUE if the comment has a parent comment otherwise FALSE. + */ + public function hasParentComment(); + + /** + * Returns the parent comment entity if this is a reply to a comment. + * + * @return \Drupal\comment\CommentInterface|NULL + * A comment entity of the parent comment or NULL if there is no parent. + */ + public function getParentComment(); + + /** + * Returns the entity to which the comment is attached. + * + * @return \Drupal\Core\Entity\EntityInterface + * The entity on which the comment is attached. + */ + public function getCommentedEntity(); + + /** + * Returns the ID of the entity to which the comment is attached. + * + * @return int + * The ID of the entity to which the comment is attached. + */ + public function getCommentedEntityId(); + + /** + * Returns the type of the entity to which the comment is attached. + * + * @return string + * An entity type. + */ + public function getCommentedEntityTypeId(); + + /** + * Returns the field ID of the comment field the comment is attached to. + * + * @return string + * The field identifier of the field the comment is attached to. + */ + public function getFieldId(); + + /** + * Sets the field ID for which this comment is attached. + * + * @param string $field_id + * The field identifier, usually formatted: {entity_type}__{field_name}, + * for example, node__comment. + * + * @return $this + * The class instance that this method is called on. + */ + public function setFieldId($field_id); + + /** + * Returns the name of the field the comment is attached to. + * + * @return string + * The name of the field the comment is attached to. + */ + public function getFieldName(); + + /** + * Returns the subject of the comment. + * + * @return string + * The subject of the comment. + */ + public function getSubject(); + + /** + * Sets the subject of the comment. + * + * @param string $subject + * The subject of the comment. + * + * @return $this + * The class instance that this method is called on. + */ + public function setSubject($subject); + + /** + * Returns the comment author's name. + * + * For anonymous authors, this is the value as typed in the comment form. + * + * @return string + * The name of the comment author. + */ + public function getAuthorName(); + + /** + * Sets the name of the author of the comment. + * + * @param string $name + * A string containing the name of the author. + * + * @return $this + * The class instance that this method is called on. + */ + public function setAuthorName($name); + + /** + * Returns the comment author's e-mail address. + * + * For anonymous authors, this is the value as typed in the comment form. + * + * @return string + * The e-mail address of the author of the comment. + */ + public function getAuthorEmail(); + + /** + * Returns the comment author's home page address. + * + * For anonymous authors, this is the value as typed in the comment form. + * + * @return string + * The homepage address of the author of the comment. + */ + public function getHomepage(); + + /** + * Sets the comment author's home page address. + * + * For anonymous authors, this is the value as typed in the comment form. + * + * @param string $homepage + * The homepage address of the author of the comment. + * + * @return $this + * The class instance that this method is called on. + */ + public function setHomepage($homepage); + + /** + * Returns the comment author's hostname. + * + * @return string + * The hostname of the author of the comment. + */ + public function getHostname(); + + /** + * Sets the hostname of the author of the comment. + * + * @param string $hostname + * The hostname of the author of the comment. + * + * @return $this + * The class instance that this method is called on. + */ + public function setHostname($hostname); + + /** + * Returns the time that the comment was created. + * + * @return int + * The timestamp of when the comment was created. + */ + public function getCreatedTime(); + + /** + * Sets the creation date of the comment. + * + * @param int $created + * The timestamp of when the comment was created. + * + * @return $this + * The class instance that this method is called on. + */ + public function setCreatedTime($created); + + /** + * Returns the timestamp of when the comment was updated. + * + * @return int + * The timestamp of when the comment was updated. + */ + public function getChangedTime(); + + /** + * Checks if the comment is published. + * + * @return bool + * TRUE if the comment is published. + */ + public function isPublished(); + + /** + * Sets the published status of the comment entity. + * + * @param bool $status + * Set to TRUE to publish the comment, FALSE to unpublish. + * + * @return \Drupal\comment\CommentInterface + * The class instance that this method is called on. + */ + public function setPublished($status); + + /** + * Returns the alphadecimal representation of the comment's place in a thread. + * + * @return string + * The alphadecimal representation of the comment's place in a thread. + */ + public function getThread(); + + /** + * Sets the alphadecimal representation of the comment's place in a thread. + * + * @param string $thread + * The alphadecimal representation of the comment's place in a thread. + * + * @return $this + * The class instance that this method is called on. + */ + public function setThread($thread); + + /** * Returns the permalink URL for this comment. * * @return array diff --git a/core/modules/comment/lib/Drupal/comment/CommentManager.php b/core/modules/comment/lib/Drupal/comment/CommentManager.php index 76b9500..2102abe 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManager.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManager.php @@ -100,8 +100,8 @@ public function __construct(FieldInfo $field_info, EntityManagerInterface $entit */ public function getParentEntityUri(CommentInterface $comment) { return $this->entityManager - ->getStorageController($comment->entity_type->value) - ->load($comment->entity_id->value) + ->getStorageController($comment->getCommentedEntityTypeId()) + ->load($comment->getCommentedEntityId()) ->urlInfo(); } @@ -142,7 +142,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', // Make sure the field doesn't already exist. if (!$this->fieldInfo->getField($entity_type, $field_name)) { // Add a default comment field for existing node comments. - $field = $this->entityManager->getStorageController('field_entity')->create(array( + $field = $this->entityManager->getStorageController('field_config')->create(array( 'entity_type' => $entity_type, 'name' => $field_name, 'type' => 'comment', @@ -153,7 +153,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', } // Make sure the instance doesn't already exist. if (!$this->fieldInfo->getInstance($entity_type, $bundle, $field_name)) { - $instance = $this->entityManager->getStorageController('field_instance')->create(array( + $instance = $this->entityManager->getStorageController('field_instance_config')->create(array( 'label' => 'Comment settings', 'description' => '', 'field_name' => $field_name, @@ -197,9 +197,9 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', */ public function addBodyField($entity_type, $field_name) { // Create the field if needed. - $field = $this->entityManager->getStorageController('field_entity')->load('comment.comment_body'); + $field = $this->entityManager->getStorageController('field_config')->load('comment.comment_body'); if (!$field) { - $field = $this->entityManager->getStorageController('field_entity')->create(array( + $field = $this->entityManager->getStorageController('field_config')->create(array( 'name' => 'comment_body', 'type' => 'text_long', 'entity_type' => 'comment', @@ -209,11 +209,11 @@ public function addBodyField($entity_type, $field_name) { // Create the instance if needed, field name defaults to 'comment'. $comment_bundle = $entity_type . '__' . $field_name; $field_instance = $this->entityManager - ->getStorageController('field_instance') + ->getStorageController('field_instance_config') ->load("comment.$comment_bundle.comment_body"); if (!$field_instance) { // Attaches the body field by default. - $field_instance = $this->entityManager->getStorageController('field_instance')->create(array( + $field_instance = $this->entityManager->getStorageController('field_instance_config')->create(array( 'field_name' => 'comment_body', 'label' => 'Comment', 'entity_type' => 'comment', diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 3ea26e6..4434b6e 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -55,9 +55,9 @@ public function updateEntityStatistics(CommentInterface $comment) { $query = $this->database->select('comment', 'c'); $query->addExpression('COUNT(cid)'); - $count = $query->condition('c.entity_id', $comment->entity_id->value) - ->condition('c.entity_type', $comment->entity_type->value) - ->condition('c.field_id', $comment->field_id->value) + $count = $query->condition('c.entity_id', $comment->getCommentedEntityId()) + ->condition('c.entity_type', $comment->getCommentedEntityTypeId()) + ->condition('c.field_id', $comment->getFieldId()) ->condition('c.status', CommentInterface::PUBLISHED) ->execute() ->fetchField(); @@ -66,9 +66,9 @@ public function updateEntityStatistics(CommentInterface $comment) { // Comments exist. $last_reply = $this->database->select('comment', 'c') ->fields('c', array('cid', 'name', 'changed', 'uid')) - ->condition('c.entity_id', $comment->entity_id->value) - ->condition('c.entity_type', $comment->entity_type->value) - ->condition('c.field_id', $comment->field_id->value) + ->condition('c.entity_id', $comment->getCommentedEntityId()) + ->condition('c.entity_type', $comment->getCommentedEntityTypeId()) + ->condition('c.field_id', $comment->getFieldId()) ->condition('c.status', CommentInterface::PUBLISHED) ->orderBy('c.created', 'DESC') ->range(0, 1) @@ -84,15 +84,15 @@ public function updateEntityStatistics(CommentInterface $comment) { 'last_comment_uid' => $last_reply->uid, )) ->key(array( - 'entity_id' => $comment->entity_id->value, - 'entity_type' => $comment->entity_type->value, - 'field_id' => $comment->field_id->value, + 'entity_id' => $comment->getCommentedEntityId(), + 'entity_type' => $comment->getCommentedEntityTypeId(), + 'field_id' => $comment->getFieldId(), )) ->execute(); } else { // Comments do not exist. - $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + $entity = $comment->getCommentedEntity(); // Get the user ID from the entity if it's set, or default to the // currently logged in user. if ($entity instanceof EntityOwnerInterface) { @@ -113,9 +113,9 @@ public function updateEntityStatistics(CommentInterface $comment) { 'last_comment_name' => '', 'last_comment_uid' => $last_comment_uid, )) - ->condition('entity_id', $comment->entity_id->value) - ->condition('entity_type', $comment->entity_type->value) - ->condition('field_id', $comment->field_id->value) + ->condition('entity_id', $comment->getCommentedEntityId()) + ->condition('entity_type', $comment->getCommentedEntityTypeId()) + ->condition('field_id', $comment->getFieldId()) ->execute(); } } @@ -125,9 +125,9 @@ public function updateEntityStatistics(CommentInterface $comment) { */ public function getMaxThread(EntityInterface $comment) { $query = $this->database->select('comment', 'c') - ->condition('entity_id', $comment->entity_id->value) - ->condition('field_id', $comment->field_id->value) - ->condition('entity_type', $comment->entity_type->value); + ->condition('entity_id', $comment->getCommentedEntityId()) + ->condition('field_id', $comment->getFieldId()) + ->condition('entity_type', $comment->getCommentedEntityTypeId()); $query->addExpression('MAX(thread)', 'thread'); return $query->execute() ->fetchField(); @@ -138,10 +138,10 @@ public function getMaxThread(EntityInterface $comment) { */ public function getMaxThreadPerThread(EntityInterface $comment) { $query = $this->database->select('comment', 'c') - ->condition('entity_id', $comment->entity_id->value) - ->condition('field_id', $comment->field_id->value) - ->condition('entity_type', $comment->entity_type->value) - ->condition('thread', $comment->pid->entity->thread->value . '.%', 'LIKE'); + ->condition('entity_id', $comment->getCommentedEntityId()) + ->condition('field_id', $comment->getFieldId()) + ->condition('entity_type', $comment->getCommentedEntityTypeId()) + ->condition('thread', $comment->getParentComment()->getThread() . '.%', 'LIKE'); $query->addExpression('MAX(thread)', 'thread'); return $query->execute() ->fetchField(); diff --git a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php index 8612170..38a9d08 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php +++ b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php @@ -86,6 +86,7 @@ public function __construct(EntityTypeInterface $entity_type, EntityManagerInter * Thrown when a comment is attached to an entity that no longer exists. */ public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL) { + /** @var \Drupal\comment\CommentInterface[] $entities */ $return = array(); if (empty($entities)) { return $return; @@ -104,23 +105,23 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang $commented_entity_ids = array(); $commented_entities = array(); foreach ($entities as $entity) { - $commented_entity_ids[$entity->entity_type->value][] = $entity->entity_id->value; + $commented_entity_ids[$entity->getCommentedEntityTypeId()][] = $entity->getCommentedEntityId(); } // Load entities in bulk. This is more performant than using - // $comment->entity_id->value as we can load them in bulk per type. + // $comment->getCommentedEntity() as we can load them in bulk per type. foreach ($commented_entity_ids as $entity_type => $entity_ids) { $commented_entities[$entity_type] = $this->entityManager->getStorageController($entity_type)->loadMultiple($entity_ids); } foreach ($entities as $entity) { - if (isset($commented_entities[$entity->entity_type->value][$entity->entity_id->value])) { - $commented_entity = $commented_entities[$entity->entity_type->value][$entity->entity_id->value]; + if (isset($commented_entities[$entity->getCommentedEntityTypeId()][$entity->getCommentedEntityId()])) { + $commented_entity = $commented_entities[$entity->getCommentedEntityTypeId()][$entity->getCommentedEntityId()]; } else { throw new \InvalidArgumentException(t('Invalid entity for comment.')); } $entity->content['#entity'] = $entity; - $entity->content['#theme'] = 'comment__' . $entity->field_id->value . '__' . $commented_entity->bundle(); + $entity->content['#theme'] = 'comment__' . $entity->getFieldId() . '__' . $commented_entity->bundle(); $entity->content['links'] = array( '#type' => 'render_cache_placeholder', '#callback' => '\Drupal\comment\CommentViewBuilder::renderLinks', @@ -204,7 +205,7 @@ public static function renderLinks(array $context) { */ protected static function buildLinks(CommentInterface $entity, EntityInterface $commented_entity) { $links = array(); - $status = $commented_entity->get($entity->field_name->value)->status; + $status = $commented_entity->get($entity->getFieldName())->status; $container = \Drupal::getContainer(); @@ -227,11 +228,11 @@ protected static function buildLinks(CommentInterface $entity, EntityInterface $ if ($entity->access('create')) { $links['comment-reply'] = array( 'title' => t('Reply'), - 'href' => "comment/reply/{$entity->entity_type->value}/{$entity->entity_id->value}/{$entity->field_name->value}/{$entity->id()}", + 'href' => "comment/reply/{$entity->getCommentedEntityId()}/{$entity->getCommentedEntityId()}/{$entity->getFieldName()}/{$entity->id()}", 'html' => TRUE, ); } - if ($entity->status->value == CommentInterface::NOT_PUBLISHED && $entity->access('approve')) { + if (!$entity->isPublished() && $entity->access('approve')) { $links['comment-approve'] = array( 'title' => t('Approve'), 'route_name' => 'comment.approve', @@ -240,7 +241,7 @@ protected static function buildLinks(CommentInterface $entity, EntityInterface $ ); } if (empty($links)) { - $links['comment-forbidden']['title'] = \Drupal::service('comment.manager')->forbiddenMessage($commented_entity, $entity->field_name->value); + $links['comment-forbidden']['title'] = \Drupal::service('comment.manager')->forbiddenMessage($commented_entity, $entity->getFieldName()); $links['comment-forbidden']['html'] = TRUE; } } @@ -270,8 +271,8 @@ protected function alterBuild(array &$build, EntityInterface $comment, EntityVie parent::alterBuild($build, $comment, $display, $view_mode, $langcode); if (empty($comment->in_preview)) { $prefix = ''; - $commented_entity = $this->entityManager->getStorageController($comment->entity_type->value)->load($comment->entity_id->value); - $instance = $this->fieldInfo->getInstance($commented_entity->getEntityTypeId(), $commented_entity->bundle(), $comment->field_name->value); + $commented_entity = $comment->getCommentedEntity(); + $instance = $this->fieldInfo->getInstance($commented_entity->getEntityTypeId(), $commented_entity->bundle(), $comment->getFieldName()); $is_threaded = isset($comment->divs) && $instance->getSetting('default_mode') == COMMENT_MODE_THREADED; diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index e299639..a302724 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -85,7 +85,7 @@ public static function create(ContainerInterface $container) { * Redirects to the permalink URL for this comment. */ public function commentApprove(CommentInterface $comment) { - $comment->status->value = CommentInterface::PUBLISHED; + $comment->setPublished(TRUE); $comment->save(); drupal_set_message($this->t('Comment approved.')); @@ -118,12 +118,12 @@ public function commentApprove(CommentInterface $comment) { * The comment listing set to the page on which the comment appears. */ public function commentPermalink(Request $request, CommentInterface $comment) { - if ($entity = $this->entityManager()->getStorageController($comment->entity_type->value)->load($comment->entity_id->value)) { + if ($entity = $this->entityManager()->getStorageController($comment->getCommentedEntityTypeId())->load($comment->getCommentedEntityId())) { // Check access permissions for the entity. if (!$entity->access('view')) { throw new AccessDeniedHttpException(); } - $instance = $this->fieldInfo->getInstance($entity->getEntityTypeId(), $entity->bundle(), $comment->field_name->value); + $instance = $this->fieldInfo->getInstance($entity->getEntityTypeId(), $entity->bundle(), $comment->getFieldName()); // Find the current display page for this comment. $page = comment_get_display_page($comment->id(), $instance); @@ -240,7 +240,7 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_ // Load the parent comment. $comment = $this->entityManager()->getStorageController('comment')->load($pid); // Check if the parent comment is published and belongs to the entity. - if (($comment->status->value == CommentInterface::NOT_PUBLISHED) || ($comment->entity_id->value != $entity->id())) { + if (!$comment->isPublished() || ($comment->getCommentedEntityId() != $entity->id())) { drupal_set_message($this->t('The comment you are replying to does not exist.'), 'error'); return $this->redirect($uri['route_name'], $uri['route_parameters']); } diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index a715fb4..a86e11c 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -19,7 +19,7 @@ /** * Defines the comment entity class. * - * @EntityType( + * @ContentEntityType( * id = "comment", * label = @Translation("Comment"), * bundle_label = @Translation("Content type"), @@ -60,156 +60,7 @@ class Comment extends ContentEntityBase implements CommentInterface { protected $threadLock = ''; /** - * The comment ID. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $cid; - - /** - * The comment UUID. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $uuid; - - /** - * The parent comment ID if this is a reply to another comment. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $pid; - - /** - * The entity ID for the entity to which this comment is attached. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $entity_id; - - /** - * The entity type of the entity to which this comment is attached. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $entity_type; - - /** - * The field to which this comment is attached. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $field_id; - - /** - * The comment language code. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $langcode; - - /** - * The comment title. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $subject; - - /** - * The comment author ID. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $uid; - - /** - * The comment author's name. - * - * For anonymous authors, this is the value as typed in the comment form. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $name; - - /** - * The comment author's e-mail address. - * - * For anonymous authors, this is the value as typed in the comment form. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $mail; - - /** - * The comment author's home page address. - * - * For anonymous authors, this is the value as typed in the comment form. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $homepage; - - /** - * The comment author's hostname. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $hostname; - - /** - * The time that the comment was created. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $created; - - /** - * The time that the comment was last edited. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $changed; - - /** - * A boolean field indicating whether the comment is published. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $status; - - /** - * The alphadecimal representation of the comment's place in a thread. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $thread; - - /** - * Initialize the object. Invoked upon construction and wake up. - */ - protected function init() { - parent::init(); - // We unset all defined properties, so magic getters apply. - unset($this->cid); - unset($this->uuid); - unset($this->pid); - unset($this->entity_id); - unset($this->field_id); - unset($this->subject); - unset($this->uid); - unset($this->name); - unset($this->mail); - unset($this->homepage); - unset($this->hostname); - unset($this->created); - unset($this->changed); - unset($this->status); - unset($this->thread); - unset($this->entity_type); - } - - /** - * Implements Drupal\Core\Entity\EntityInterface::id(). + * {@inheritdoc} */ public function id() { return $this->get('cid')->value; @@ -221,23 +72,21 @@ public function id() { public function preSave(EntityStorageControllerInterface $storage_controller) { parent::preSave($storage_controller); - if (!isset($this->status->value)) { - $this->status->value = \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED; + if (is_null($this->get('status')->value)) { + $published = \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED; + $this->setPublished($published); } if ($this->isNew()) { // Add the comment to database. This next section builds the thread field. // Also see the documentation for comment_view(). - if (!empty($this->thread->value)) { - // Allow calling code to set thread itself. - $thread = $this->thread->value; - } - else { + $thread = $this->getThread(); + if (empty($thread)) { if ($this->threadLock) { // As preSave() is protected, this can only happen when this class // is extended in a faulty manner. throw new \LogicException('preSave is called again without calling postSave() or releaseThreadLock()'); } - if ($this->pid->target_id == 0) { + if (!$this->hasParentComment()) { // This is a comment with no parent comment (depth 0): we start // by retrieving the maximum thread level. $max = $storage_controller->getMaxThread($this); @@ -253,10 +102,10 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { // the thread value at the proper depth. // Get the parent comment: - $parent = $this->pid->entity; + $parent = $this->getParentComment(); // Strip the "/" from the end of the parent thread. - $parent->thread->value = (string) rtrim((string) $parent->thread->value, '/'); - $prefix = $parent->thread->value . '.'; + $parent->setThread((string) rtrim((string) $parent->getThread(), '/')); + $prefix = $parent->getThread() . '.'; // Get the max value in *this* thread. $max = $storage_controller->getMaxThreadPerThread($this); @@ -271,7 +120,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { $max = rtrim($max, '/'); // Get the value at the correct depth. $parts = explode('.', $max); - $parent_depth = count(explode('.', $parent->thread->value)); + $parent_depth = count(explode('.', $parent->getThread())); $n = Number::alphadecimalToInt($parts[$parent_depth]); } } @@ -280,24 +129,24 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { // has the lock, just move to the next integer. do { $thread = $prefix . Number::intToAlphadecimal(++$n) . '/'; - $lock_name = "comment:{$this->entity_id->value}:$thread"; + $lock_name = "comment:{$this->getCommentedEntityId()}:$thread"; } while (!\Drupal::lock()->acquire($lock_name)); $this->threadLock = $lock_name; } - if (empty($this->created->value)) { - $this->created->value = REQUEST_TIME; + if (is_null($this->getCreatedTime())) { + $this->setCreatedTime(REQUEST_TIME); } - if (empty($this->changed->value)) { - $this->changed->value = $this->created->value; + if (is_null($this->getChangedTime())) { + $this->set('changed', $this->getCreatedTime()); } // We test the value with '===' because we need to modify anonymous // users as well. if ($this->getOwnerId() === \Drupal::currentUser()->id() && \Drupal::currentUser()->isAuthenticated()) { - $this->name->value = \Drupal::currentUser()->getUsername(); + $this->setAuthorName(\Drupal::currentUser()->getUsername()); } // Add the values which aren't passed into the function. - $this->thread->value = $thread; - $this->hostname->value = \Drupal::request()->getClientIP(); + $this->setThread($thread); + $this->setHostname(\Drupal::request()->getClientIP()); } } @@ -310,8 +159,8 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $ $this->releaseThreadLock(); // Update the {comment_entity_statistics} table prior to executing the hook. $storage_controller->updateEntityStatistics($this); - if ($this->status->value == CommentInterface::PUBLISHED) { - module_invoke_all('comment_publish', $this); + if ($this->isPublished()) { + \Drupal::moduleHandler()->invokeAll('comment_publish', array($this)); } } @@ -343,7 +192,7 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont * {@inheritdoc} */ public function permalink() { - $entity = entity_load($this->get('entity_type')->value, $this->get('entity_id')->value); + $entity = $this->getCommentedEntity(); $uri = $entity->urlInfo(); $uri['options'] = array('fragment' => 'comment-' . $this->id()); @@ -380,7 +229,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['subject'] = FieldDefinition::create('string') ->setLabel(t('Subject')) - ->setDescription(t('The comment title or subject.')); + ->setDescription(t('The comment title or subject.')) + ->setSetting('max_length', 64); $fields['uid'] = FieldDefinition::create('entity_reference') ->setLabel(t('User ID')) @@ -393,19 +243,27 @@ public static function baseFieldDefinitions($entity_type) { $fields['name'] = FieldDefinition::create('string') ->setLabel(t('Name')) ->setDescription(t("The comment author's name.")) - ->setSetting('default_value', ''); + ->setSettings(array( + 'default_value' => '', + 'max_length' => 60, + )) + ->setConstraints(array('CommentName' => array())); $fields['mail'] = FieldDefinition::create('email') ->setLabel(t('Email')) ->setDescription(t("The comment author's e-mail address.")); - $fields['homepage'] = FieldDefinition::create('string') + $fields['homepage'] = FieldDefinition::create('uri') ->setLabel(t('Homepage')) - ->setDescription(t("The comment author's home page address.")); + ->setDescription(t("The comment author's home page address.")) + // URIs are not length limited by RFC 2616, but we can only store 255 + // characters in our comment DB schema. + ->setSetting('max_length', 255); $fields['hostname'] = FieldDefinition::create('string') ->setLabel(t('Hostname')) - ->setDescription(t("The comment author's hostname.")); + ->setDescription(t("The comment author's hostname.")) + ->setSetting('max_length', 128); // @todo Convert to a "created" field in https://drupal.org/node/2145103. $fields['created'] = FieldDefinition::create('integer') @@ -424,13 +282,14 @@ public static function baseFieldDefinitions($entity_type) { $fields['thread'] = FieldDefinition::create('string') ->setLabel(t('Thread place')) - ->setDescription(t("The alphadecimal representation of the comment's place in a thread, consisting of a base 36 string prefixed by an integer indicating its length.")); + ->setDescription(t("The alphadecimal representation of the comment's place in a thread, consisting of a base 36 string prefixed by an integer indicating its length.")) + ->setSetting('max_length', 255); $fields['entity_type'] = FieldDefinition::create('string') ->setLabel(t('Entity type')) ->setDescription(t('The entity type to which this comment is attached.')); - // @todo Convert to aa entity_reference field in + // @todo Convert to the entity_reference field in // https://drupal.org/node/2149859. $fields['field_id'] = FieldDefinition::create('string') ->setLabel(t('Field ID')) @@ -451,8 +310,192 @@ public static function baseFieldDefinitions($entity_type) { /** * {@inheritdoc} */ + public function hasParentComment() { + $parent = $this->get('pid')->entity; + return !empty($parent); + } + + /** + * {@inheritdoc} + */ + public function getParentComment() { + return $this->get('pid')->entity; + } + + /** + * {@inheritdoc} + */ + public function getCommentedEntity() { + $entity_id = $this->getCommentedEntityId(); + $entity_type = $this->getCommentedEntityTypeId(); + return entity_load($entity_type, $entity_id); + } + + /** + * {@inheritdoc} + */ + public function getCommentedEntityId() { + return $this->get('entity_id')->value; + } + + /** + * {@inheritdoc} + */ + public function getCommentedEntityTypeId() { + return $this->get('entity_type')->value; + } + + /** + * {@inheritdoc} + */ + public function getFieldId() { + return $this->get('field_id')->value; + } + + /** + * {@inheritdoc} + */ + public function setFieldId($field_id) { + $this->set('field_id', $field_id); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getFieldName() { + return $this->get('field_name')->value; + } + + /** + * {@inheritdoc} + */ + public function getSubject() { + return $this->get('subject')->value; + } + + /** + * {@inheritdoc} + */ + public function setSubject($subject) { + $this->set('subject', $subject); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getAuthorName() { + return $this->get('name')->value ?: \Drupal::config('user.settings')->get('anonymous'); + } + + /** + * {@inheritdoc} + */ + public function setAuthorName($name) { + $this->set('name', $name); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getAuthorEmail() { + $mail = $this->get('mail')->value; + + if ($this->get('uid')->target_id != 0) { + $mail = $this->get('uid')->entity->getEmail(); + } + + return $mail; + } + + /** + * {@inheritdoc} + */ + public function getHomepage() { + return $this->get('homepage')->value; + } + + /** + * {@inheritdoc} + */ + public function setHomepage($homepage) { + $this->set('homepage', $homepage); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getHostname() { + return $this->get('hostname')->value; + } + + /** + * {@inheritdoc} + */ + public function setHostname($hostname) { + $this->set('hostname', $hostname); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getCreatedTime() { + if (isset($this->get('created')->value)) { + return $this->get('created')->value; + } + return NULL; + } + + /** + * {@inheritdoc} + */ + public function setCreatedTime($created) { + $this->set('created', $created); + return $this; + } + + /** + * {@inheritdoc} + */ + public function isPublished() { + return $this->get('status')->value == CommentInterface::PUBLISHED; + } + + /** + * {@inheritdoc} + */ + public function setPublished($status) { + $this->set('status', $status ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getThread() { + $thread = $this->get('thread'); + if (!empty($thread->value)) { + return $thread->value; + } + } + + /** + * {@inheritdoc} + */ + public function setThread($thread) { + $this->set('thread', $thread); + return $this; + } + + /** + * {@inheritdoc} + */ public function getChangedTime() { - return $this->changed->value; + return $this->get('changed')->value; } /** diff --git a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php index ebd2623..3f5caef 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php +++ b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php @@ -183,7 +183,7 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { $commented_entities = array(); foreach ($comments as $comment) { - $commented_entity_ids[$comment->entity_type->value][] = $comment->entity_id->value; + $commented_entity_ids[$comment->getCommentedEntityTypeId()][] = $comment->getCommentedEntityId(); } foreach ($commented_entity_ids as $entity_type => $ids) { @@ -191,8 +191,8 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { } foreach ($comments as $comment) { - /** @var $commented_entity \Drupal\comment\CommentInterface */ - $commented_entity = $commented_entities[$comment->entity_type->value][$comment->entity_id->value]; + /** @var $commented_entity \Drupal\Core\Entity\EntityInterface */ + $commented_entity = $commented_entities[$comment->getCommentedEntityTypeId()][$comment->getCommentedEntityId()]; $commented_entity_uri = $commented_entity->urlInfo(); $username = array( '#theme' => 'username', @@ -204,11 +204,11 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { } $comment_permalink = $comment->permalink(); $options[$comment->id()] = array( - 'title' => array('data' => array('#title' => $comment->subject->value ?: $comment->id())), + 'title' => array('data' => array('#title' => $comment->getSubject() ?: $comment->id())), 'subject' => array( 'data' => array( '#type' => 'link', - '#title' => $comment->subject->value, + '#title' => $comment->getSubject(), '#route_name' => $comment_permalink['route_name'], '#route_parameters' => $comment_permalink['route_parameters'], '#options' => $comment_permalink['options'] + array( @@ -229,7 +229,7 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { '#access' => $commented_entity->access('view'), ), ), - 'changed' => $this->date->format($comment->changed->value, 'short'), + 'changed' => $this->date->format($comment->getChangedTime(), 'short'), ); $comment_uri = $comment->urlInfo(); $links = array(); @@ -290,12 +290,12 @@ public function submitForm(array &$form, array &$form_state) { // see \Drupal\comment\Controller\AdminController::adminPage(). if ($operation == 'unpublish') { $comment = $this->commentStorage->load($cid); - $comment->status->value = CommentInterface::NOT_PUBLISHED; + $comment->setPublished(FALSE); $comment->save(); } elseif ($operation == 'publish') { $comment = $this->commentStorage->load($cid); - $comment->status->value = CommentInterface::PUBLISHED; + $comment->setPublished(TRUE); $comment->save(); } } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php index cd3ab53..41ed873 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/PublishComment.php @@ -25,7 +25,7 @@ class PublishComment extends ActionBase { * {@inheritdoc} */ public function execute($comment = NULL) { - $comment->status->value = CommentInterface::PUBLISHED; + $comment->setPublished(TRUE); $comment->save(); } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php index 876850c..92d4014 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishByKeywordComment.php @@ -29,7 +29,7 @@ public function execute($comment = NULL) { $text = drupal_render($build); foreach ($this->configuration['keywords'] as $keyword) { if (strpos($text, $keyword) !== FALSE) { - $comment->status->value = CommentInterface::NOT_PUBLISHED; + $comment->setPublished(FALSE); $comment->save(); break; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php index d15c324..74d565a 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Action/UnpublishComment.php @@ -25,7 +25,7 @@ class UnpublishComment extends ActionBase { * {@inheritdoc} */ public function execute($comment = NULL) { - $comment->status->value = CommentInterface::NOT_PUBLISHED; + $comment->setPublished(FALSE); $comment->save(); } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Validation/Constraint/CommentNameConstraint.php b/core/modules/comment/lib/Drupal/comment/Plugin/Validation/Constraint/CommentNameConstraint.php new file mode 100644 index 0000000..575a393 --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Validation/Constraint/CommentNameConstraint.php @@ -0,0 +1,24 @@ +value; + if (isset($author_name) && $author_name !== '') { + // Do not allow unauthenticated comment authors to use a name that is + // taken by a registered user. + if ($field_item->getEntity()->getOwnerId() === 0) { + // @todo Properly inject dependency https://drupal.org/node/2197029 + $users = \Drupal::entityManager()->getStorageController('user')->loadByProperties(array('name' => $author_name)); + if (!empty($users)) { + $this->context->addViolation($constraint->message, array('%name' => $author_name)); + } + } + } + } + +} diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Link.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Link.php index adba10b..9c667ce 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Link.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Link.php @@ -102,6 +102,7 @@ public function render(ResultRow $values) { */ protected function renderLink($data, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : t('view'); + /** @var \Drupal\comment\CommentInterface $comment */ $comment = $data; $cid = $comment->id(); @@ -114,9 +115,7 @@ protected function renderLink($data, ResultRow $values) { } // If there is no comment link to the node. elseif ($this->options['link_to_node']) { - $entity_id = $comment->entity_id; - $entity_type = $comment->entity_type; - $entity = $this->entityManager->getStorageController($entity_type)->load($entity_id); + $entity = $comment->getCommentedEntity(); $this->options['alter']['path'] = $entity->getSystemPath(); } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php index aefb38d..1c64d75 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php @@ -43,7 +43,7 @@ protected function renderLink($data, ResultRow $values) { $comment = $this->getEntity($values); $this->options['alter']['make_link'] = TRUE; - $this->options['alter']['path'] = "comment/reply/{$comment->entity_type->value}/{$comment->entity_id->value}/{$comment->field_name->value}/{$comment->id()}"; + $this->options['alter']['path'] = "comment/reply/{$comment->getCommentedEntityTypeId()}/{$comment->getCommentedEntityId()}/{$comment->getFieldName()}/{$comment->id()}"; return $text; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/row/CommentRow.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/row/CommentRow.php index 6caa523..2d34728 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/row/CommentRow.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/row/CommentRow.php @@ -45,8 +45,7 @@ public function buildOptionsForm(&$form, &$form_state) { * {@inheritdoc} */ public function render($row) { - $entity_id = $row->{$this->field_alias}; - $build = $this->build[$entity_id]; + $build = parent::render($row); if (!$this->options['links']) { unset($build['links']); } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php index 4fbfc76..063738c 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php @@ -61,7 +61,7 @@ public function preRender($result) { $this->comments = entity_load_multiple('comment', $cids); foreach ($this->comments as $comment) { - $comment->depth = count(explode('.', $comment->thread->value)) - 1; + $comment->depth = count(explode('.', $comment->getThread())) - 1; } } @@ -111,11 +111,11 @@ public function render($row) { $comment->rss_elements = array( array( 'key' => 'pubDate', - 'value' => gmdate('r', $comment->created->value), + 'value' => gmdate('r', $comment->getCreatedTime()), ), array( 'key' => 'dc:creator', - 'value' => $comment->name->value, + 'value' => $comment->getAuthorName(), ), array( 'key' => 'guid', diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/wizard/Comment.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/wizard/Comment.php index e63ae15..09fb54e 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/wizard/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/wizard/Comment.php @@ -140,12 +140,15 @@ protected function defaultDisplayOptions() { // Add permission-based access control. $display_options['access']['type'] = 'perm'; + $display_options['access']['provider'] = 'user'; // Add a relationship to nodes. $display_options['relationships']['node']['id'] = 'node'; $display_options['relationships']['node']['table'] = 'comment'; $display_options['relationships']['node']['field'] = 'node'; $display_options['relationships']['node']['required'] = 1; + $display_options['relationships']['node']['plugin_id'] = 'standard'; + $display_options['relationships']['node']['provider'] = 'views'; // Remove the default fields, since we are customizing them here. unset($display_options['fields']); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php index ea892c8..667d278 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php @@ -41,12 +41,12 @@ function testCommentPublishUnpublishActions() { // Unpublish a comment. $action = entity_load('action', 'comment_unpublish_action'); $action->execute(array($comment)); - $this->assertEqual($comment->status->value, CommentInterface::NOT_PUBLISHED, 'Comment was unpublished'); + $this->assertTrue($comment->isPublished() === FALSE, 'Comment was unpublished'); // Publish a comment. $action = entity_load('action', 'comment_publish_action'); $action->execute(array($comment)); - $this->assertEqual($comment->status->value, CommentInterface::PUBLISHED, 'Comment was published'); + $this->assertTrue($comment->isPublished() === TRUE, 'Comment was published'); } /** @@ -72,10 +72,10 @@ function testCommentUnpublishByKeyword() { // Load the full comment so that status is available. $comment = comment_load($comment->id()); - $this->assertTrue($comment->status->value == CommentInterface::PUBLISHED, 'The comment status was set to published.'); + $this->assertTrue($comment->isPublished() === TRUE, 'The comment status was set to published.'); $action->execute(array($comment)); - $this->assertTrue($comment->status->value == CommentInterface::NOT_PUBLISHED, 'The comment status was set to not published.'); + $this->assertTrue($comment->isPublished() === FALSE, 'The comment status was set to not published.'); } } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php index 9fa5ea8..a7b28a7 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Tests; use Drupal\Component\Utility\String; +use Drupal\Core\Cache\Cache; /** * Tests the Comment module blocks. @@ -66,7 +67,7 @@ function testRecentCommentBlock() { user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access comments')); // drupalCreateNode() does not automatically flush content caches unlike // posting a node from a node form. - cache_invalidate_tags(array('content' => TRUE)); + Cache::invalidateTags(array('content' => TRUE)); $this->drupalGet(''); $this->assertNoText(t('Recent comments')); user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments')); @@ -78,23 +79,23 @@ function testRecentCommentBlock() { $this->assertText(t('Recent comments')); // Test the only the 10 latest comments are shown and in the proper order. - $this->assertNoText($comments[10]->subject->value, 'Comment 11 not found in block.'); + $this->assertNoText($comments[10]->getSubject(), 'Comment 11 not found in block.'); for ($i = 0; $i < 10; $i++) { - $this->assertText($comments[$i]->subject->value, String::format('Comment @number found in block.', array('@number' => 10 - $i))); + $this->assertText($comments[$i]->getSubject(), String::format('Comment @number found in block.', array('@number' => 10 - $i))); if ($i > 1) { $previous_position = $position; - $position = strpos($this->drupalGetContent(), $comments[$i]->subject->value); + $position = strpos($this->drupalGetContent(), $comments[$i]->getSubject()); $this->assertTrue($position > $previous_position, String::format('Comment @a appears after comment @b', array('@a' => 10 - $i, '@b' => 11 - $i))); } - $position = strpos($this->drupalGetContent(), $comments[$i]->subject->value); + $position = strpos($this->drupalGetContent(), $comments[$i]->getSubject()); } // Test that links to comments work when comments are across pages. $this->setCommentsPerPage(1); for ($i = 0; $i < 10; $i++) { - $this->clickLink($comments[$i]->subject->value); - $this->assertText($comments[$i]->subject->value, 'Comment link goes to correct page.'); + $this->clickLink($comments[$i]->getSubject()); + $this->assertText($comments[$i]->getSubject(), 'Comment link goes to correct page.'); $this->assertRaw('drupalCreateNode(array('type' => 'article', 'uid' => $case['node_uid'])); // Add a comment. + /** @var \Drupal\comment\CommentInterface $comment */ $comment = entity_create('comment', array( 'entity_id' => $node->id(), 'entity_type' => 'node', @@ -132,7 +133,7 @@ function testCommentClasses() { // comment that was created or changed after the last time the current // user read the corresponding node. if ($case['comment_status'] == CommentInterface::PUBLISHED || $case['user'] == 'admin') { - $this->assertIdentical(1, count($this->xpath('//*[contains(@class, "comment")]/*[@data-comment-timestamp="' . $comment->changed->value . '"]')), 'data-comment-timestamp attribute is set on comment'); + $this->assertIdentical(1, count($this->xpath('//*[contains(@class, "comment")]/*[@data-comment-timestamp="' . $comment->getChangedTime() . '"]')), 'data-comment-timestamp attribute is set on comment'); $expectedJS = ($case['user'] !== 'anonymous'); $this->assertIdentical($expectedJS, isset($settings['ajaxPageState']['js']['core/modules/comment/js/comment-new-indicator.js']), 'drupal.comment-new-indicator library is present.'); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php index c0b2aaf..10c8f80 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php @@ -60,7 +60,7 @@ function testCommentDefaultFields() { // Test adding a field that defaults to COMMENT_CLOSED. $this->container->get('comment.manager')->addDefaultField('node', 'test_node_type', 'who_likes_ponies', COMMENT_CLOSED); - $field = entity_load('field_instance', 'node.test_node_type.who_likes_ponies'); + $field = entity_load('field_instance_config', 'node.test_node_type.who_likes_ponies'); $this->assertEqual($field->default_value[0]['status'], COMMENT_CLOSED); } @@ -73,7 +73,7 @@ function testCommentInstallAfterContentModule() { $this->drupalLogin($this->admin_user); // Drop default comment field added in CommentTestBase::setup(). - entity_load('field_entity', 'node.comment')->delete(); + entity_load('field_config', 'node.comment')->delete(); if ($field = $this->container->get('field.info')->getField('node', 'comment_node_forum')) { $field->delete(); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php index 5f7c735..65c5f26 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@ -75,24 +75,24 @@ function testCommentInterface() { $this->drupalGet('comment/' . $comment->id() . '/edit'); $this->assertTitle(t('Edit comment @title | Drupal', array( - '@title' => $comment->subject->value, + '@title' => $comment->getSubject(), ))); // Test changing the comment author to "Anonymous". - $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => '')); - $this->assertTrue(empty($comment->name->value) && $comment->getOwnerId() == 0, 'Comment author successfully changed to anonymous.'); + $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), array('name' => '')); + $this->assertTrue($comment->getAuthorName() == t('Anonymous') && $comment->getOwnerId() == 0, 'Comment author successfully changed to anonymous.'); // Test changing the comment author to an unverified user. $random_name = $this->randomName(); $this->drupalGet('comment/' . $comment->id() . '/edit'); - $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => $random_name)); + $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), array('name' => $random_name)); $this->drupalGet('node/' . $this->node->id()); $this->assertText($random_name . ' (' . t('not verified') . ')', 'Comment author successfully changed to an unverified user.'); // Test changing the comment author to a verified user. $this->drupalGet('comment/' . $comment->id() . '/edit'); - $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => $this->web_user->getUsername())); - $this->assertTrue($comment->name->value == $this->web_user->getUsername() && $comment->getOwnerId() == $this->web_user->id(), 'Comment author successfully changed to a registered user.'); + $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), array('name' => $this->web_user->getUsername())); + $this->assertTrue($comment->getAuthorName() == $this->web_user->getUsername() && $comment->getOwnerId() == $this->web_user->id(), 'Comment author successfully changed to a registered user.'); $this->drupalLogout(); @@ -110,29 +110,29 @@ function testCommentInterface() { $reply = $this->postComment(NULL, $this->randomName(), '', TRUE); $reply_loaded = comment_load($reply->id()); $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.'); - $this->assertEqual($comment->id(), $reply_loaded->pid->target_id, 'Pid of a reply to a comment is set correctly.'); + $this->assertEqual($comment->id(), $reply_loaded->getParentComment()->id(), 'Pid of a reply to a comment is set correctly.'); // Check the thread of reply grows correctly. - $this->assertEqual(rtrim($comment->thread->value, '/') . '.00/', $reply_loaded->thread->value); + $this->assertEqual(rtrim($comment->getThread(), '/') . '.00/', $reply_loaded->getThread()); // Second reply to comment #2 creating comment #4. $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment->id()); - $this->assertText($comment->subject->value, 'Individual comment-reply subject found.'); + $this->assertText($comment->getSubject(), 'Individual comment-reply subject found.'); $this->assertText($comment->comment_body->value, 'Individual comment-reply body found.'); $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); $reply_loaded = comment_load($reply->id()); $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.'); // Check the thread of second reply grows correctly. - $this->assertEqual(rtrim($comment->thread->value, '/') . '.01/', $reply_loaded->thread->value); + $this->assertEqual(rtrim($comment->getThread(), '/') . '.01/', $reply_loaded->getThread()); // Reply to comment #4 creating comment #5. $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $reply_loaded->id()); - $this->assertText($reply_loaded->subject->value, 'Individual comment-reply subject found.'); + $this->assertText($reply_loaded->getSubject(), 'Individual comment-reply subject found.'); $this->assertText($reply_loaded->comment_body->value, 'Individual comment-reply body found.'); $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); $reply_loaded = comment_load($reply->id()); $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.'); // Check the thread of reply to second reply grows correctly. - $this->assertEqual(rtrim($comment->thread->value, '/') . '.01.00/', $reply_loaded->thread->value); + $this->assertEqual(rtrim($comment->getThread(), '/') . '.01.00/', $reply_loaded->getThread()); // Edit reply. $this->drupalGet('comment/' . $reply->id() . '/edit'); @@ -148,7 +148,7 @@ function testCommentInterface() { $this->setCommentsPerPage(50); // Attempt to reply to an unpublished comment. - $reply_loaded->status->value = CommentInterface::NOT_PUBLISHED; + $reply_loaded->setPublished(FALSE); $reply_loaded->save(); $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $reply_loaded->id()); $this->assertText(t('The comment you are replying to does not exist.'), 'Replying to an unpublished comment'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php index 17e358c..99b1495 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php @@ -88,6 +88,7 @@ public function testCommentNewCommentsIndicator() { // Create a new comment. This helper function may be run with different // comment settings so use $comment->save() to avoid complex setup. + /** @var \Drupal\comment\CommentInterface $comment */ $comment = entity_create('comment', array( 'cid' => NULL, 'entity_id' => $this->node->id(), @@ -111,7 +112,7 @@ public function testCommentNewCommentsIndicator() { // value, the drupal.node-new-comments-link library would determine that the // node received a comment after the user last viewed it, and hence it would // perform an HTTP request to render the "new comments" node link. - $this->assertIdentical(1, count($this->xpath('//*[@data-history-node-last-comment-timestamp="' . $comment->changed->value . '"]')), 'data-history-node-last-comment-timestamp attribute is set to the correct value.'); + $this->assertIdentical(1, count($this->xpath('//*[@data-history-node-last-comment-timestamp="' . $comment->getChangedTime() . '"]')), 'data-history-node-last-comment-timestamp attribute is set to the correct value.'); $this->assertIdentical(1, count($this->xpath('//*[@data-history-node-field-name="comment"]')), 'data-history-node-field-name attribute is set to the correct value.'); $response = $this->renderNewCommentsNodeLinks(array($this->node->id())); $this->assertResponse(200); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeChangesTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeChangesTest.php index 89abd33..a6c8129 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeChangesTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeChangesTest.php @@ -31,11 +31,11 @@ function testNodeDeletion() { $this->assertFalse(comment_load($comment->id()), 'The comment could not be loaded after the node was deleted.'); // Make sure the comment field and all its instances are deleted when node // type is deleted. - $this->assertNotNull(entity_load('field_entity', 'node.comment'), 'Comment field exists'); - $this->assertNotNull(entity_load('field_instance', 'node.article.comment'), 'Comment instance exists'); + $this->assertNotNull(entity_load('field_config', 'node.comment'), 'Comment field exists'); + $this->assertNotNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance exists'); // Delete the node type. entity_delete_multiple('node_type', array($this->node->bundle())); - $this->assertNull(entity_load('field_entity', 'node.comment'), 'Comment field deleted'); - $this->assertNull(entity_load('field_instance', 'node.article.comment'), 'Comment instance deleted'); + $this->assertNull(entity_load('field_config', 'node.comment'), 'Comment field deleted'); + $this->assertNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance deleted'); } } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php index e2b4597..82338b1 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php @@ -157,12 +157,12 @@ function postComment(EntityInterface $entity, $comment, $subject = '', $contact function commentExists(CommentInterface $comment = NULL, $reply = FALSE) { if ($comment) { $regex = '/' . ($reply ? '
(.*?)' : ''); - $regex .= 'subject->value . '(.*?)'; // Match subject. - $regex .= $comment->comment_body->value . '(.*?)'; // Match comment. + $regex .= 'getSubject() . '(.*?)'; + $regex .= $comment->comment_body->value . '(.*?)'; $regex .= '/s'; - return (boolean)preg_match($regex, $this->drupalGetContent()); + return (boolean) preg_match($regex, $this->drupalGetContent()); } else { return FALSE; @@ -328,7 +328,7 @@ function testCommentFunctionality() { $this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment/' . $comment1->id()); $this->assertText('You are not authorized to view comments'); - $this->assertNoText($comment1->subject->value, 'Comment not displayed.'); + $this->assertNoText($comment1->getSubject(), 'Comment not displayed.'); // Test comment field widget changes. $limited_user = $this->drupalCreateUser(array( diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php index e72ed99..1de62da 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php @@ -136,20 +136,20 @@ function testCommentEditPreviewSave() { // Check that the saved comment is still correct. $comment_loaded = comment_load($comment->id(), TRUE); - $this->assertEqual($comment_loaded->subject->value, $edit['subject'], 'Subject loaded.'); + $this->assertEqual($comment_loaded->getSubject(), $edit['subject'], 'Subject loaded.'); $this->assertEqual($comment_loaded->comment_body->value, $edit['comment_body[0][value]'], 'Comment body loaded.'); - $this->assertEqual($comment_loaded->name->value, $edit['name'], 'Name loaded.'); - $this->assertEqual($comment_loaded->created->value, $raw_date, 'Date loaded.'); + $this->assertEqual($comment_loaded->getAuthorName(), $edit['name'], 'Name loaded.'); + $this->assertEqual($comment_loaded->getCreatedTime(), $raw_date, 'Date loaded.'); $this->drupalLogout(); // Check that the date and time of the comment are correct when edited by // non-admin users. $user_edit = array(); - $expected_created_time = $comment_loaded->created->value; + $expected_created_time = $comment_loaded->getCreatedTime(); $this->drupalLogin($web_user); $this->drupalPostForm('comment/' . $comment->id() . '/edit', $user_edit, t('Save')); $comment_loaded = comment_load($comment->id(), TRUE); - $this->assertEqual($comment_loaded->created->value, $expected_created_time, 'Expected date and time for comment edited.'); + $this->assertEqual($comment_loaded->getCreatedTime(), $expected_created_time, 'Expected date and time for comment edited.'); $this->drupalLogout(); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentStatisticsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentStatisticsTest.php index 07ca1bd..6906b55 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentStatisticsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentStatisticsTest.php @@ -106,7 +106,7 @@ function testCommentNodeCommentStatistics() { // Checks the new values of node comment statistics with comment #3. // The node needs to be reloaded with a node_load_multiple cache reset. $node = node_load($this->node->id(), TRUE); - $this->assertEqual($node->get('comment')->last_comment_name, $comment_loaded->name->value, 'The value of node last_comment_name is the name of the anonymous user.'); + $this->assertEqual($node->get('comment')->last_comment_name, $comment_loaded->getAuthorName(), 'The value of node last_comment_name is the name of the anonymous user.'); $this->assertEqual($node->get('comment')->last_comment_uid, 0, 'The value of node last_comment_uid is zero.'); $this->assertEqual($node->get('comment')->comment_count, 2, 'The value of node comment_count is 2.'); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php index 1613bcc..c1edf13 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php @@ -179,12 +179,12 @@ public function postComment($entity, $comment, $subject = '', $contact = NULL, $ function commentExists(CommentInterface $comment = NULL, $reply = FALSE) { if ($comment) { $regex = '/' . ($reply ? '
(.*?)' : ''); - $regex .= 'subject->value . '(.*?)'; // Match subject. - $regex .= $comment->comment_body->value . '(.*?)'; // Match comment. + $regex .= 'getSubject() . '(.*?)'; + $regex .= $comment->comment_body->value . '(.*?)'; $regex .= '/s'; - return (boolean)preg_match($regex, $this->drupalGetContent()); + return (boolean) preg_match($regex, $this->drupalGetContent()); } else { return FALSE; diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php index 6874fff..f69b55f 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php @@ -44,7 +44,7 @@ function testCommentThreading() { $comment1 = $this->postComment($this->node, $comment_text, $subject_text, TRUE); // Confirm that the comment was created and has the correct threading. $this->assertTrue($this->commentExists($comment1), 'Comment #1. Comment found.'); - $this->assertEqual($comment1->thread->value, '01/'); + $this->assertEqual($comment1->getThread(), '01/'); // Confirm that there is no reference to a parent comment. $this->assertNoParentLink($comment1->id()); @@ -54,7 +54,7 @@ function testCommentThreading() { $comment2 = $this->postComment(NULL, $this->randomName(), '', TRUE); // Confirm that the comment was created and has the correct threading. $this->assertTrue($this->commentExists($comment2, TRUE), 'Comment #2. Reply found.'); - $this->assertEqual($comment2->thread->value, '01.00/'); + $this->assertEqual($comment2->getThread(), '01.00/'); // Confirm that there is a link to the parent comment. $this->assertParentLink($comment2->id(), $comment1->id()); @@ -63,7 +63,7 @@ function testCommentThreading() { $comment3 = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); // Confirm that the comment was created and has the correct threading. $this->assertTrue($this->commentExists($comment3, TRUE), 'Comment #3. Second reply found.'); - $this->assertEqual($comment3->thread->value, '01.00.00/'); + $this->assertEqual($comment3->getThread(), '01.00.00/'); // Confirm that there is a link to the parent comment. $this->assertParentLink($comment3->id(), $comment2->id()); @@ -73,7 +73,7 @@ function testCommentThreading() { $comment4 = $this->postComment(NULL, $this->randomName(), '', TRUE); // Confirm that the comment was created and has the correct threading. $this->assertTrue($this->commentExists($comment4), 'Comment #4. Third reply found.'); - $this->assertEqual($comment4->thread->value, '01.01/'); + $this->assertEqual($comment4->getThread(), '01.01/'); // Confirm that there is a link to the parent comment. $this->assertParentLink($comment4->id(), $comment1->id()); @@ -84,7 +84,7 @@ function testCommentThreading() { $comment5 = $this->postComment($this->node, $comment_text, $subject_text, TRUE); // Confirm that the comment was created and has the correct threading. $this->assertTrue($this->commentExists($comment5), 'Comment #5. Second comment found.'); - $this->assertEqual($comment5->thread->value, '02/'); + $this->assertEqual($comment5->getThread(), '02/'); // Confirm that there is no link to a parent comment. $this->assertNoParentLink($comment5->id()); @@ -94,7 +94,7 @@ function testCommentThreading() { $comment6 = $this->postComment(NULL, $this->randomName(), '', TRUE); // Confirm that the comment was created and has the correct threading. $this->assertTrue($this->commentExists($comment6, TRUE), 'Comment #6. Reply found.'); - $this->assertEqual($comment6->thread->value, '02.00/'); + $this->assertEqual($comment6->getThread(), '02.00/'); // Confirm that there is a link to the parent comment. $this->assertParentLink($comment6->id(), $comment5->id()); @@ -103,7 +103,7 @@ function testCommentThreading() { $comment7 = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); // Confirm that the comment was created and has the correct threading. $this->assertTrue($this->commentExists($comment7, TRUE), 'Comment #7. Second reply found.'); - $this->assertEqual($comment7->thread->value, '02.00.00/'); + $this->assertEqual($comment7->getThread(), '02.00.00/'); // Confirm that there is a link to the parent comment. $this->assertParentLink($comment7->id(), $comment6->id()); @@ -113,7 +113,7 @@ function testCommentThreading() { $comment8 = $this->postComment(NULL, $this->randomName(), '', TRUE); // Confirm that the comment was created and has the correct threading. $this->assertTrue($this->commentExists($comment8), 'Comment #8. Third reply found.'); - $this->assertEqual($comment8->thread->value, '02.01/'); + $this->assertEqual($comment8->getThread(), '02.01/'); // Confirm that there is a link to the parent comment. $this->assertParentLink($comment8->id(), $comment5->id()); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php index a09da3a..081775f 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php @@ -45,27 +45,28 @@ function testCommentTokenReplacement() { $this->drupalGet('comment/reply/node/' . $node->id() . '/comment/' . $parent_comment->id()); $child_comment = $this->postComment(NULL, $this->randomName(), $this->randomName()); $comment = comment_load($child_comment->id()); - $comment->homepage->value = 'http://example.org/'; + $comment->setHomepage('http://example.org/'); // Add HTML to ensure that sanitation of some fields tested directly. - $comment->subject->value = 'Blinking Comment'; + $comment->setSubject('Blinking Comment'); // Generate and test sanitized tokens. $tests = array(); $tests['[comment:cid]'] = $comment->id(); - $tests['[comment:hostname]'] = check_plain($comment->hostname->value); - $tests['[comment:name]'] = filter_xss($comment->name->value); + $tests['[comment:hostname]'] = check_plain($comment->getHostname()); + $tests['[comment:name]'] = filter_xss($comment->getAuthorName()); + $tests['[comment:author]'] = filter_xss($comment->getAuthorName()); $tests['[comment:mail]'] = check_plain($this->admin_user->getEmail()); - $tests['[comment:homepage]'] = check_url($comment->homepage->value); - $tests['[comment:title]'] = filter_xss($comment->subject->value); + $tests['[comment:homepage]'] = check_url($comment->getHomepage()); + $tests['[comment:title]'] = filter_xss($comment->getSubject()); $tests['[comment:body]'] = $comment->comment_body->processed; $tests['[comment:url]'] = url('comment/' . $comment->id(), $url_options + array('fragment' => 'comment-' . $comment->id())); $tests['[comment:edit-url]'] = url('comment/' . $comment->id() . '/edit', $url_options); - $tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->created->value, 2, $language_interface->id); - $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->changed->value, 2, $language_interface->id); - $tests['[comment:parent:cid]'] = $comment->pid->target_id; - $tests['[comment:parent:title]'] = check_plain($parent_comment->subject->value); - $tests['[comment:node:nid]'] = $comment->entity_id->value; + $tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->getCreatedTime(), 2, $language_interface->id); + $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->getChangedTime(), 2, $language_interface->id); + $tests['[comment:parent:cid]'] = $comment->hasParentComment() ? $comment->getParentComment()->id() : NULL; + $tests['[comment:parent:title]'] = check_plain($parent_comment->getSubject()); + $tests['[comment:node:nid]'] = $comment->getCommentedEntityId(); $tests['[comment:node:title]'] = check_plain($node->getTitle()); $tests['[comment:author:uid]'] = $comment->getOwnerId(); $tests['[comment:author:name]'] = check_plain($this->admin_user->getUsername()); @@ -79,13 +80,14 @@ function testCommentTokenReplacement() { } // Generate and test unsanitized tokens. - $tests['[comment:hostname]'] = $comment->hostname->value; - $tests['[comment:name]'] = $comment->name->value; + $tests['[comment:hostname]'] = $comment->getHostname(); + $tests['[comment:name]'] = $comment->getAuthorName(); + $tests['[comment:author]'] = $comment->getAuthorName(); $tests['[comment:mail]'] = $this->admin_user->getEmail(); - $tests['[comment:homepage]'] = $comment->homepage->value; - $tests['[comment:title]'] = $comment->subject->value; + $tests['[comment:homepage]'] = $comment->getHomepage(); + $tests['[comment:title]'] = $comment->getSubject(); $tests['[comment:body]'] = $comment->comment_body->value; - $tests['[comment:parent:title]'] = $parent_comment->subject->value; + $tests['[comment:parent:title]'] = $parent_comment->getSubject(); $tests['[comment:node:title]'] = $node->getTitle(); $tests['[comment:author:name]'] = $this->admin_user->getUsername(); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentValidationTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentValidationTest.php new file mode 100644 index 0000000..5f7e03f --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentValidationTest.php @@ -0,0 +1,141 @@ + 'Comment Validation', + 'description' => 'Tests the comment validation constraints.', + 'group' => 'Comment', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $this->installSchema('node', array('node', 'node_field_data', 'node_field_revision', 'node_revision')); + } + + /** + * Tests the comment validation constraints. + */ + public function testValidation() { + // Add comment field to content. + $this->entityManager->getStorageController('field_config')->create(array( + 'entity_type' => 'node', + 'name' => 'comment', + 'type' => 'comment', + ))->save(); + // Add comment field instance to page content. + $this->entityManager->getStorageController('field_instance_config')->create(array( + 'field_name' => 'comment', + 'entity_type' => 'node', + 'bundle' => 'page', + 'label' => 'Comment settings', + ))->save(); + + $node = $this->entityManager->getStorageController('node')->create(array( + 'type' => 'page', + 'title' => 'test', + )); + $node->save(); + + $comment = $this->entityManager->getStorageController('comment')->create(array( + 'entity_id' => $node->id(), + 'entity_type' => 'node', + 'field_name' => 'comment', + )); + + $violations = $comment->validate(); + $this->assertEqual(count($violations), 0, 'No violations when validating a default comment.'); + + $comment->set('subject', $this->randomString(65)); + $this->assertLengthViolation($comment, 'subject', 64); + + // Make the subject valid. + $comment->set('subject', $this->randomString()); + $comment->set('name', $this->randomString(61)); + $this->assertLengthViolation($comment, 'name', 60); + + // Validate a name collision between an anonymous comment author name and an + // existing user account name. + $user = entity_create('user', array('name' => 'test')); + $user->save(); + $comment->set('name', 'test'); + $violations = $comment->validate(); + $this->assertEqual(count($violations), 1, "Violation found on author name collision"); + $this->assertEqual($violations[0]->getPropertyPath(), "name"); + $this->assertEqual($violations[0]->getMessage(), t('%name belongs to a registered user.', array('%name' => 'test'))); + + // Make the name valid. + $comment->set('name', 'valid unused name'); + $comment->set('mail', 'invalid'); + $violations = $comment->validate(); + $this->assertEqual(count($violations), 1, 'Violation found when email is invalid'); + $this->assertEqual($violations[0]->getPropertyPath(), 'mail.0.value'); + $this->assertEqual($violations[0]->getMessage(), t('This value is not a valid email address.')); + + $comment->set('mail', NULL); + $comment->set('homepage', 'http://example.com/' . $this->randomName(237)); + $this->assertLengthViolation($comment, 'homepage', 255); + + $comment->set('homepage', 'invalid'); + $violations = $comment->validate(); + $this->assertEqual(count($violations), 1, 'Violation found when homepage is invalid'); + $this->assertEqual($violations[0]->getPropertyPath(), 'homepage.0.value'); + + // @todo This message should be improved in https://drupal.org/node/2012690 + $this->assertEqual($violations[0]->getMessage(), t('This value should be of the correct primitive type.')); + + $comment->set('homepage', NULL); + $comment->set('hostname', $this->randomString(129)); + $this->assertLengthViolation($comment, 'hostname', 128); + + $comment->set('hostname', NULL); + $comment->set('thread', $this->randomString(256)); + $this->assertLengthViolation($comment, 'thread', 255); + } + + /** + * Verifies that a length violation exists for the given field. + * + * @param \Drupal\comment\CommentInterface $comment + * The comment object to validate. + * @param string $field_name + * The field that violates the maximum length. + * @param int $length + * Number of characters that was exceeded. + */ + protected function assertLengthViolation(CommentInterface $comment, $field_name, $length) { + $violations = $comment->validate(); + $this->assertEqual(count($violations), 1, "Violation found when $field_name is too long."); + $this->assertEqual($violations[0]->getPropertyPath(), "$field_name.0.value"); + $this->assertEqual($violations[0]->getMessage(), t('This value is too long. It should have %limit characters or less.', array('%limit' => $length))); + } + +} diff --git a/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php b/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php index 4ec7428..e7e699c 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php @@ -90,13 +90,13 @@ public function setUp() { 'entity_id' => $this->node->id(), )); $comment->setOwnerId(0); - $comment->subject->value = 'Test comment ' . $i; + $comment->setSubject('Test comment ' . $i); $comment->comment_body->value = 'Test body ' . $i; $comment->comment_body->format = 'full_html'; // Ensure comments are sorted in ascending order. $time = REQUEST_TIME + ($this->masterDisplayResults - $i); - $comment->created->value = $time; + $comment->setCreatedTime($time); $comment->changed->value = $time; $comment->save(); @@ -125,10 +125,10 @@ public function testBlockDisplay() { ); $expected_result = array(); foreach (array_values($this->commentsCreated) as $key => $comment) { - $expected_result[$key]['entity_id'] = $comment->entity_id->value; - $expected_result[$key]['subject'] = $comment->subject->value; + $expected_result[$key]['entity_id'] = $comment->getCommentedEntityId(); + $expected_result[$key]['subject'] = $comment->getSubject(); $expected_result[$key]['cid'] = $comment->id(); - $expected_result[$key]['created'] = $comment->created->value; + $expected_result[$key]['created'] = $comment->getCreatedTime(); } $this->assertIdenticalResultset($view, $expected_result, $map); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/Views/RowRssTest.php b/core/modules/comment/lib/Drupal/comment/Tests/Views/RowRssTest.php index d0cd727..2cee7a1 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/Views/RowRssTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/Views/RowRssTest.php @@ -38,7 +38,7 @@ public function testRssRow() { $result = $this->xpath('//item'); $this->assertEqual(count($result), 1, 'Just one comment was found in the rss output.'); - $this->assertEqual($result[0]->pubdate, gmdate('r', $this->comment->created->value), 'The right pubDate appears in the rss output.'); + $this->assertEqual($result[0]->pubdate, gmdate('r', $this->comment->getCreatedTime()), 'The right pubDate appears in the rss output.'); } } diff --git a/core/modules/comment/tests/Drupal/comment/Tests/Entity/CommentLockTest.php b/core/modules/comment/tests/Drupal/comment/Tests/Entity/CommentLockTest.php index d5f2eee..a0afe1a 100644 --- a/core/modules/comment/tests/Drupal/comment/Tests/Entity/CommentLockTest.php +++ b/core/modules/comment/tests/Drupal/comment/Tests/Entity/CommentLockTest.php @@ -4,9 +4,8 @@ * Contains \Drupal\comment\Tests\Entity\CommentTest */ -namespace Drupal\comment\Tests\Entity { +namespace Drupal\comment\Tests\Entity; -use Drupal\comment\Entity\Comment; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Tests\UnitTestCase; @@ -14,6 +13,7 @@ * Unit tests for the comment entity lock behavior. * * @group Drupal + * @group Comment */ class CommentLockTest extends UnitTestCase { @@ -33,11 +33,12 @@ public static function getInfo() { */ public function testLocks() { $container = new ContainerBuilder(); + $container->set('module_handler', $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface')); $container->set('current_user', $this->getMock('Drupal\Core\Session\AccountInterface')); $container->register('request', 'Symfony\Component\HttpFoundation\Request'); $lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface'); $cid = 2; - $lock_name = "comment:$cid:01.00/"; + $lock_name = "comment:$cid:.00/"; $lock->expects($this->at(0)) ->method('acquire') ->with($lock_name, 30) @@ -60,26 +61,25 @@ public function testLocks() { $comment->expects($this->once()) ->method('isNew') ->will($this->returnValue(TRUE)); - foreach (array('status', 'pid', 'created', 'changed', 'entity_id', 'uid', 'thread', 'hostname') as $property) { - $comment->$property = new \stdClass(); - } - $comment->status->value = 1; - $comment->entity_id->value = $cid; - $comment->uid->target_id = 3; - // Parent comment is the first in thread. - $comment->pid->target_id = 42; - $comment->pid->entity = new \stdClass(); - $comment->pid->entity->thread = (object) array('value' => '01/'); + $comment->expects($this->once()) + ->method('hasParentComment') + ->will($this->returnValue(TRUE)); + $comment->expects($this->once()) + ->method('getParentComment') + ->will($this->returnValue($comment)); + $comment->expects($this->once()) + ->method('getCommentedEntityId') + ->will($this->returnValue($cid)); + $comment->expects($this->any()) + ->method('getThread') + ->will($this->returnValue('')); + $comment->expects($this->at(0)) + ->method('get') + ->with('status') + ->will($this->returnValue((object) array('value' => NULL))); $storage_controller = $this->getMock('Drupal\comment\CommentStorageControllerInterface'); $comment->preSave($storage_controller); $comment->postSave($storage_controller); } } -} -namespace { -if (!function_exists('module_invoke_all')) { - function module_invoke_all() {} -} -} - diff --git a/core/modules/comment/tests/modules/comment_test/comment_test.module b/core/modules/comment/tests/modules/comment_test/comment_test.module index 10f521b..7ff9376 100644 --- a/core/modules/comment/tests/modules/comment_test/comment_test.module +++ b/core/modules/comment/tests/modules/comment_test/comment_test.module @@ -9,15 +9,15 @@ use Drupal\comment\CommentInterface; /** - * Implements hook_entity_info_alter(). + * Implements hook_entity_type_alter(). */ -function comment_test_entity_info_alter(&$entity_info) { - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ +function comment_test_entity_type_alter(array &$entity_types) { + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ if (\Drupal::languageManager()->isMultilingual()) { // Enable language handling for comment fields. - $translation = $entity_info['comment']->get('translation'); + $translation = $entity_types['comment']->get('translation'); $translation['comment_test'] = TRUE; - $entity_info['comment']->set('translation', $translation); + $entity_types['comment']->set('translation', $translation); } } diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml index 5a50bbf..c2de92e 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml @@ -141,4 +141,3 @@ module: views id: test_comment_row tag: '' langcode: en -uuid: fb77b691-eeef-4ac8-8382-15f5fd25aae0 diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml index e6facd9..44245b7 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml @@ -64,5 +64,4 @@ label: test_comment_rss module: views id: test_comment_rss tag: '' -uuid: 0a29eea8-0dc4-45bd-a6d2-4b3ae711c7d4 langcode: und diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_user_uid.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_user_uid.yml index e518584..e8cb5dc 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_user_uid.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_user_uid.yml @@ -51,5 +51,4 @@ id: test_comment_user_uid tag: default base_field: nid module: comment_test_views -uuid: 8f8244da-6e5e-4a8c-a17a-13ae6a3e4a88 langcode: und diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSync.php b/core/modules/config/lib/Drupal/config/Form/ConfigSync.php index 95e4650..98992fc 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSync.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSync.php @@ -11,9 +11,8 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Lock\LockBackendInterface; +use Drupal\Core\Config\BatchConfigImporter; use Drupal\Core\Config\StorageComparer; -use Drupal\Core\Config\ConfigImporter; -use Drupal\Core\Config\ConfigException; use Drupal\Core\Config\TypedConfigManager; use Drupal\Core\Routing\UrlGeneratorInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -218,7 +217,7 @@ public function buildForm(array $form, array &$form_state) { * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - $config_importer = new ConfigImporter( + $config_importer = new BatchConfigImporter( $form_state['storage_comparer'], $this->eventDispatcher, $this->configManager, @@ -229,21 +228,59 @@ public function submitForm(array &$form, array &$form_state) { drupal_set_message($this->t('Another request may be synchronizing configuration already.')); } else{ - try { - $config_importer->import(); - drupal_flush_all_caches(); - drupal_set_message($this->t('The configuration was imported successfully.')); - } - catch (ConfigException $e) { - // Return a negative result for UI purposes. We do not differentiate - // between an actual synchronization error and a failed lock, because - // concurrent synchronizations are an edge-case happening only when - // multiple developers or site builders attempt to do it without - // coordinating. - watchdog_exception('config_import', $e); - drupal_set_message($this->t('The import failed due to an error. Any errors have been logged.'), 'error'); - } + $config_importer->initialize(); + $batch = array( + 'operations' => array( + array(array(get_class($this), 'processBatch'), array($config_importer)), + ), + 'finished' => array(get_class($this), 'finishBatch'), + 'title' => t('Synchronizing configuration'), + 'init_message' => t('Starting configuration synchronization.'), + 'progress_message' => t('Synchronized @current configuration files out of @total.'), + 'error_message' => t('Configuration synchronization has encountered an error.'), + 'file' => drupal_get_path('module', 'config') . '/config.admin.inc', + ); + + batch_set($batch); + } + } + + /** + * Processes the config import batch and persists the importer. + * + * @param BatchConfigImporter $config_importer + * The batch config importer object to persist. + * @param $context + * The batch context. + */ + public static function processBatch(BatchConfigImporter $config_importer, &$context) { + if (!isset($context['sandbox']['config_importer'])) { + $context['sandbox']['config_importer'] = $config_importer; } + + $config_importer = $context['sandbox']['config_importer']; + $config_importer->processBatch($context); + } + + /** + * Finish batch. + * + * This function is a static function to avoid serialising the ConfigSync + * object unnecessarily. + */ + public static function finishBatch($success, $results, $operations) { + if ($success) { + drupal_set_message(\Drupal::translation()->translate('The configuration was imported successfully.')); + } + else { + // An error occurred. + // $operations contains the operations that remained unprocessed. + $error_operation = reset($operations); + $message = \Drupal::translation()->translate('An error occurred while processing %error_operation with arguments: @arguments', array('%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE))); + drupal_set_message($message, 'error'); + } + drupal_flush_all_caches(); } + } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php index 564218a..bfa8304 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php @@ -128,7 +128,7 @@ public function testExport() { // Spot check several known simple configuration files. $element = $this->xpath('//select[@name="config_name"]'); $options = $this->getAllOptions($element[0]); - $expected_options = array('filter.settings', 'system.site', 'user.settings'); + $expected_options = array('system.site', 'user.settings'); foreach ($options as &$option) { $option = (string) $option; } diff --git a/core/modules/config/tests/config_other_module_config/config/config_test.dynamic.other_module.yml b/core/modules/config/tests/config_other_module_config/config/config_test.dynamic.other_module.yml index 7bd70d2..b56ac6d 100644 --- a/core/modules/config/tests/config_other_module_config/config/config_test.dynamic.other_module.yml +++ b/core/modules/config/tests/config_other_module_config/config/config_test.dynamic.other_module.yml @@ -1,5 +1,4 @@ id: other_module -uuid: 486f9f5c-82ed-4add-a700-b0ee3af4d17d label: 'Other module' weight: 0 style: '' diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index 4fb13e3..0a16756 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -64,18 +64,18 @@ function config_test_config_test_create(ConfigTest $config_test) { } /** - * Implements hook_entity_info_alter(). + * Implements hook_entity_type_alter(). */ -function config_test_entity_info_alter(&$entity_info) { - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ +function config_test_entity_type_alter(array &$entity_types) { + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ // The 'translatable' entity key is not supposed to change over time. In this // case we can safely do it because we set it once and we do not change it for // all the duration of the test session. - $entity_info['config_test']->set('translatable', \Drupal::service('state')->get('config_test.translatable')); + $entity_types['config_test']->set('translatable', \Drupal::service('state')->get('config_test.translatable')); // Create a clone of config_test that does not have a status. - $entity_info['config_test_no_status'] = clone $entity_info['config_test']; - $config_test_no_status = &$entity_info['config_test_no_status']; + $entity_types['config_test_no_status'] = clone $entity_types['config_test']; + $config_test_no_status = &$entity_types['config_test_no_status']; $config_test_no_status->setLinkTemplate('edit-form', 'config_test.entity_config_test_no_status'); $config_test_no_status->setLinkTemplate('delete-form', 'config_test.entity_delete_config_test_no_status'); diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigQueryTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigQueryTest.php index c781d22..8c37a49 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigQueryTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigQueryTest.php @@ -10,7 +10,7 @@ /** * Defines the ConfigQueryTest configuration entity used by the query test. * - * @EntityType( + * @ConfigEntityType( * id = "config_query_test", * label = @Translation("Test configuration for query"), * controllers = { diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php index 623fa14..36d7fbf 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php @@ -13,7 +13,7 @@ /** * Defines the ConfigTest configuration entity. * - * @EntityType( + * @ConfigEntityType( * id = "config_test", * label = @Translation("Test configuration"), * controllers = { diff --git a/core/modules/config_translation/config_translation.api.php b/core/modules/config_translation/config_translation.api.php index 03a502c..a7db185 100644 --- a/core/modules/config_translation/config_translation.api.php +++ b/core/modules/config_translation/config_translation.api.php @@ -52,7 +52,7 @@ function hook_config_translation_info(&$info) { if ($entity_type->isFieldable() && !empty($base_route)) { $info[$entity_type_id . '_fields'] = array( 'base_route_name' => 'field_ui.instance_edit_' . $entity_type_id, - 'entity_type' => 'field_instance', + 'entity_type' => 'field_instance_config', 'title' => t('!label field'), 'class' => '\Drupal\config_translation\ConfigFieldInstanceMapper', 'base_entity_type' => $entity_type_id, diff --git a/core/modules/config_translation/config_translation.module b/core/modules/config_translation/config_translation.module index 1415b69..077e0cd 100644 --- a/core/modules/config_translation/config_translation.module +++ b/core/modules/config_translation/config_translation.module @@ -85,18 +85,18 @@ function config_translation_theme() { } /** - * Implements hook_entity_info_alter(). + * Implements hook_entity_type_alter(). */ -function config_translation_entity_info_alter($entity_info) { - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ - foreach ($entity_info as $entity_type_id => $entity_type) { +function config_translation_entity_type_alter(array &$entity_types) { + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ + foreach ($entity_types as $entity_type_id => $entity_type) { if ($entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) { if ($entity_type_id == 'block') { $class = 'Drupal\config_translation\Controller\ConfigTranslationBlockListController'; } - elseif ($entity_type_id == 'field_instance') { + elseif ($entity_type_id == 'field_instance_config') { $class = 'Drupal\config_translation\Controller\ConfigTranslationFieldInstanceListController'; - // Will be filled in dynamically, see \Drupal\field\Entity\FieldInstance::linkTemplates(). + // Will be filled in dynamically, see \Drupal\field\Entity\FieldInstanceConfig::linkTemplates(). $entity_type->setLinkTemplate('drupal:config-translation-overview', 'config_translation.item.overview.'); } else { @@ -135,7 +135,7 @@ function config_translation_config_translation_info(&$info) { if ($entity_type->isFieldable() && !empty($base_route)) { $info[$entity_type_id . '_fields'] = array( 'base_route_name' => 'field_ui.instance_edit_' . $entity_type_id, - 'entity_type' => 'field_instance', + 'entity_type' => 'field_instance_config', 'title' => '!label field', 'class' => '\Drupal\config_translation\ConfigFieldInstanceMapper', 'base_entity_type' => $entity_type_id, diff --git a/core/modules/config_translation/tests/modules/config_translation_test/config_translation_test.module b/core/modules/config_translation/tests/modules/config_translation_test/config_translation_test.module index ac6fb3f..5c4f5d4 100644 --- a/core/modules/config_translation/tests/modules/config_translation_test/config_translation_test.module +++ b/core/modules/config_translation/tests/modules/config_translation_test/config_translation_test.module @@ -6,12 +6,12 @@ */ /** - * Implements hook_entity_info_alter(). + * Implements hook_entity_type_alter(). */ -function config_translation_test_entity_info_alter(&$entity_info) { +function config_translation_test_entity_type_alter(array &$entity_types) { // Remove entity definition for these entity types from config_test module. - unset($entity_info['config_test_no_status']); - unset($entity_info['config_query_test']); + unset($entity_types['config_test_no_status']); + unset($entity_types['config_query_test']); } /** diff --git a/core/modules/contact/config/contact.category.feedback.yml b/core/modules/contact/config/contact.category.feedback.yml index a82a24e..8fb7765 100644 --- a/core/modules/contact/config/contact.category.feedback.yml +++ b/core/modules/contact/config/contact.category.feedback.yml @@ -1,5 +1,4 @@ id: feedback -uuid: 29821a98-2498-4161-8d00-e4dba46dd1e8 label: 'Website feedback' recipients: { } reply: '' diff --git a/core/modules/contact/config/contact.category.personal.yml b/core/modules/contact/config/contact.category.personal.yml index c41cc94..2fc59f1 100644 --- a/core/modules/contact/config/contact.category.personal.yml +++ b/core/modules/contact/config/contact.category.personal.yml @@ -1,5 +1,4 @@ id: personal -uuid: 4520a81c-a103-4b4d-b000-e95741044672 label: 'Personal contact form' recipients: { } reply: '' diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index a3246a3..bd9454f 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -100,11 +100,11 @@ function contact_menu_link_defaults() { } /** - * Implements hook_entity_info_alter(). + * Implements hook_entity_type_alter(). */ -function contact_entity_info_alter(&$entity_info) { - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ - $entity_info['user']->setLinkTemplate('contact-form', 'contact.personal_page'); +function contact_entity_type_alter(array &$entity_types) { + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ + $entity_types['user']->setLinkTemplate('contact-form', 'contact.personal_page'); } /** diff --git a/core/modules/contact/lib/Drupal/contact/CategoryListController.php b/core/modules/contact/lib/Drupal/contact/CategoryListController.php index 1e62630..e68789b 100644 --- a/core/modules/contact/lib/Drupal/contact/CategoryListController.php +++ b/core/modules/contact/lib/Drupal/contact/CategoryListController.php @@ -6,6 +6,7 @@ namespace Drupal\contact; +use Drupal\Component\Utility\String; use Drupal\Core\Config\Entity\ConfigEntityListController; use Drupal\Core\Entity\EntityInterface; @@ -35,7 +36,7 @@ public function buildRow(EntityInterface $entity) { $row['selected'] = t('No'); } else { - $row['recipients'] = check_plain(implode(', ', $entity->recipients)); + $row['recipients'] = String::checkPlain(implode(', ', $entity->recipients)); $default_category = \Drupal::config('contact.settings')->get('default_category'); $row['selected'] = ($default_category == $entity->id() ? t('Yes') : t('No')); } diff --git a/core/modules/contact/lib/Drupal/contact/CategoryStorageController.php b/core/modules/contact/lib/Drupal/contact/CategoryStorageController.php deleted file mode 100644 index 90b74db..0000000 --- a/core/modules/contact/lib/Drupal/contact/CategoryStorageController.php +++ /dev/null @@ -1,17 +0,0 @@ -getUsername(); $form['name']['#required'] = FALSE; - $form['name']['#markup'] = check_plain($user->getUsername()); + $form['name']['#markup'] = String::checkPlain($user->getUsername()); $form['mail']['#type'] = 'item'; $form['mail']['#value'] = $user->getEmail(); $form['mail']['#required'] = FALSE; - $form['mail']['#markup'] = check_plain($user->getEmail()); + $form['mail']['#markup'] = String::checkPlain($user->getEmail()); } // The user contact form has a preset recipient. diff --git a/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php b/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php index 4feeb4f..5e5b6dd 100644 --- a/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php +++ b/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityViewBuilder; +use Drupal\Component\Utility\String; /** * Render controller for contact messages. @@ -28,7 +29,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang $entity->content['message'] = array( '#type' => 'item', '#title' => t('Message'), - '#markup' => check_plain($entity->getMessage()), + '#markup' => String::checkPlain($entity->getMessage()), ); } } diff --git a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php index b8ae287..126fc75 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php @@ -20,7 +20,7 @@ class ContactSitewideTest extends WebTestBase { * * @var array */ - public static $modules = array('contact', 'field_ui'); + public static $modules = array('text', 'contact', 'field_ui'); public static function getInfo() { return array( diff --git a/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php index 709449c..368f1ad 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php @@ -25,7 +25,7 @@ class ContactFieldsTest extends ViewTestBase { /** * Contains the field definition array attached to contact used for this test. * - * @var \Drupal\field\Entity\Field + * @var \Drupal\field\Entity\FieldConfig */ protected $field; @@ -40,14 +40,14 @@ public static function getInfo() { protected function setUp() { parent::setUp(); - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'name' => strtolower($this->randomName()), 'entity_type' => 'contact_message', 'type' => 'text' )); $this->field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $this->field->name, 'entity_type' => 'contact_message', 'bundle' => 'contact_message', diff --git a/core/modules/contact/tests/modules/contact_test_views/test_views/views.view.test_contact_link.yml b/core/modules/contact/tests/modules/contact_test_views/test_views/views.view.test_contact_link.yml index a42573f..e060a63 100644 --- a/core/modules/contact/tests/modules/contact_test_views/test_views/views.view.test_contact_link.yml +++ b/core/modules/contact/tests/modules/contact_test_views/test_views/views.view.test_contact_link.yml @@ -126,5 +126,4 @@ label: test_contact_link module: views id: test_contact_link tag: '' -uuid: 41459805-9045-477c-aa37-f7e6d60b4132 langcode: en diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index a8a88ed..13c81eb 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -5,6 +5,7 @@ * The content translation administration forms. */ +use Drupal\Component\Utility\String; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; @@ -194,10 +195,10 @@ function _content_translation_preprocess_language_content_settings_table(&$varia 'bundle' => array( '#prefix' => '', '#suffix' => ' ', - '#markup' => check_plain($element[$bundle]['settings']['#label']), + '#markup' => String::checkPlain($element[$bundle]['settings']['#label']), ), 'field' => array( - '#markup' => check_plain($field_element['#label']), + '#markup' => String::checkPlain($field_element['#label']), ), ), 'class' => array('field'), @@ -228,15 +229,15 @@ function _content_translation_preprocess_language_content_settings_table(&$varia 'bundle' => array( '#prefix' => '', '#suffix' => ' ', - '#markup' => check_plain($element[$bundle]['settings']['#label']), + '#markup' => String::checkPlain($element[$bundle]['settings']['#label']), ), 'field' => array( '#prefix' => '', '#suffix' => ' ', - '#markup' => check_plain($field_element['#label']), + '#markup' => String::checkPlain($field_element['#label']), ), 'columns' => array( - '#markup' => check_plain($column_label), + '#markup' => String::checkPlain($column_label), ), ), 'class' => array('column'), diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 57461cc..f2aa2bb 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -55,7 +55,7 @@ function content_translation_module_implements_alter(&$implementations, $hook) { switch ($hook) { // Move some of our hook implementations to the end of the list. case 'menu_alter': - case 'entity_info_alter': + case 'entity_type_alter': $group = $implementations['content_translation']; unset($implementations['content_translation']); $implementations['content_translation'] = $group; @@ -74,10 +74,10 @@ function content_translation_language_types_info_alter(array &$language_types) { } /** - * Implements hook_entity_info_alter(). + * Implements hook_entity_type_alter(). * * The content translation UI relies on the entity info to provide its features. - * See the documentation of hook_entity_info() in the Entity API documentation + * See the documentation of hook_entity_type_build() in the Entity API documentation * for more details on all the entity info keys that may be defined. * * To make Content Translation automatically support an entity type some keys @@ -100,24 +100,24 @@ function content_translation_language_types_info_alter(array &$language_types) { * * @see \Drupal\Core\Entity\Annotation\EntityType */ -function content_translation_entity_info_alter(array &$entity_info) { +function content_translation_entity_type_alter(array &$entity_types) { // Provide defaults for translation info. - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ - foreach ($entity_info as $entity_type => &$info) { - if ($info->isTranslatable()) { - if (!$info->hasControllerClass('translation')) { - $info->setControllerClass('translation', 'Drupal\content_translation\ContentTranslationController'); + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ + foreach ($entity_types as $entity_type) { + if ($entity_type->isTranslatable()) { + if (!$entity_type->hasControllerClass('translation')) { + $entity_type->setControllerClass('translation', 'Drupal\content_translation\ContentTranslationController'); } - $translation = $info->get('translation'); + $translation = $entity_type->get('translation'); if (!$translation || !isset($translation['content_translation'])) { $translation['content_translation'] = array(); } - if ($info->hasLinkTemplate('canonical')) { + if ($entity_type->hasLinkTemplate('canonical')) { // Provide default route names for the translation paths. - if (!$info->hasLinkTemplate('drupal:content-translation-overview')) { - $info->setLinkTemplate('drupal:content-translation-overview', "content_translation.translation_overview_$entity_type"); + if (!$entity_type->hasLinkTemplate('drupal:content-translation-overview')) { + $entity_type->setLinkTemplate('drupal:content-translation-overview', "content_translation.translation_overview_" . $entity_type->id()); } // @todo Remove this as soon as menu access checks rely on the // controller. See https://drupal.org/node/2155787. @@ -125,7 +125,7 @@ function content_translation_entity_info_alter(array &$entity_info) { 'access_callback' => 'content_translation_translate_access', ); } - $info->set('translation', $translation); + $entity_type->set('translation', $translation); } } } diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc index 3272296..0b6a4dc 100644 --- a/core/modules/content_translation/content_translation.pages.inc +++ b/core/modules/content_translation/content_translation.pages.inc @@ -15,7 +15,8 @@ * @param \Drupal\Core\Entity\EntityInterface $entity * The entity whose translation overview should be displayed. * - * @deprecated Use \Drupal\content_translation\Controller\ContentTranslationController::overview() + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\content_translation\Controller\ContentTranslationController::overview(). */ function content_translation_overview(EntityInterface $entity) { $controller = content_translation_controller($entity->getEntityTypeId()); @@ -178,7 +179,8 @@ function _content_translation_get_switch_links($path) { * @return array * A processed form array ready to be rendered. * - * @deprecated Use \Drupal\content_translation\Controller\ContentTranslationController::add() + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\content_translation\Controller\ContentTranslationController::add(). */ function content_translation_add_page(EntityInterface $entity, Language $source = NULL, Language $target = NULL) { $source = !empty($source) ? $source : $entity->language(); @@ -204,7 +206,8 @@ function content_translation_add_page(EntityInterface $entity, Language $source * @return array * A processed form array ready to be rendered. * - * @deprecated Use \Drupal\content_translation\Controller\ContentTranslationController::edit() + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\content_translation\Controller\ContentTranslationController::edit(). */ function content_translation_edit_page(EntityInterface $entity, Language $language = NULL) { $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php index e5bb277..a8e1a0c 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php @@ -188,13 +188,13 @@ function testFieldTranslatableSettingsUI() { 'entity_type' => 'node', 'type' => 'text', ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => 'article_text', 'entity_type' => 'node', 'bundle' => 'article', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); // Tests that field instance doesn't have translatable setting if bundle // is not translatable. diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php index 259e4a2..3f990db 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php @@ -56,7 +56,7 @@ protected function setupTestFields() { $this->fieldName = 'field_test_et_ui_image'; $this->cardinality = 3; - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => $this->fieldName, 'entity_type' => $this->entityTypeId, 'type' => 'image', @@ -64,7 +64,7 @@ protected function setupTestFields() { 'translatable' => TRUE, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => $this->entityTypeId, 'field_name' => $this->fieldName, 'bundle' => $this->entityTypeId, diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php index cb478d3..c753114 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php @@ -17,6 +17,13 @@ abstract class ContentTranslationTestBase extends WebTestBase { /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('text'); + + /** * The entity type being tested. * * @var string @@ -168,14 +175,14 @@ protected function enableTranslation() { protected function setupTestFields() { $this->fieldName = 'field_test_et_ui_test'; - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => $this->fieldName, 'type' => 'text', 'entity_type' => $this->entityTypeId, 'cardinality' => 1, 'translatable' => TRUE, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => $this->entityTypeId, 'field_name' => $this->fieldName, 'bundle' => $this->bundle, diff --git a/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php b/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php index 7a40df1..2f6004a 100644 --- a/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php +++ b/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php @@ -9,6 +9,7 @@ use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\ResultRow; +use Drupal\Component\Utility\Json; /** * Provides a handler that adds contextual links. @@ -114,7 +115,7 @@ public function render(ResultRow $values) { '', array(), array( - 'contextual-views-field-links' => drupal_encode_path(drupal_json_encode($links)), + 'contextual-views-field-links' => drupal_encode_path(Json::encode($links)), ) ) ); diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index ccf1a0c..27b52e4 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -46,7 +46,8 @@ function datetime_element_info() { $types['datetime'] = array( '#input' => TRUE, '#element_validate' => array('datetime_datetime_validate'), - '#process' => array('datetime_datetime_form_process'), + '#process' => array('datetime_datetime_form_process', 'form_process_group'), + '#pre_render' => array('form_pre_render_group'), '#theme' => 'datetime_form', '#theme_wrappers' => array('datetime_wrapper'), '#date_date_format' => $date_format, @@ -991,11 +992,11 @@ function datetime_form_node_form_alter(&$form, &$form_state, $form_id) { $format_type = datetime_default_format_type(); // Alter the 'Authored on' date to use datetime. - $form['author']['date']['#type'] = 'datetime'; + $form['created']['#type'] = 'datetime'; $date_format = entity_load('date_format', 'html_date')->getPattern($format_type); $time_format = entity_load('date_format', 'html_time')->getPattern($format_type); - $form['author']['date']['#description'] = t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($date_format . ' ' . $time_format))); - unset($form['author']['date']['#maxlength']); + $form['created']['#description'] = t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($date_format . ' ' . $time_format))); + unset($form['created']['#maxlength']); } /** diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php index 4aeec85..94ff1ae 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php @@ -26,14 +26,14 @@ class DateTimeFieldTest extends WebTestBase { /** * A field to use in this test class. * - * @var \Drupal\field\Entity\Field + * @var \Drupal\field\Entity\FieldConfig */ protected $field; /** * The instance used in this test class. * - * @var \Drupal\field\Entity\FieldInstance + * @var \Drupal\field\Entity\FieldInstanceConfig */ protected $instance; @@ -58,14 +58,14 @@ function setUp() { $this->drupalLogin($web_user); // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'entity_test', 'type' => 'datetime', 'settings' => array('datetime_type' => 'date'), )); $this->field->save(); - $this->instance = entity_create('field_instance', array( + $this->instance = entity_create('field_instance_config', array( 'field_name' => $this->field->name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -296,7 +296,7 @@ function testDefaultValue() { $this->drupalCreateContentType(array('type' => 'date_content')); // Create a field with settings to validate. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'node', 'type' => 'datetime', @@ -304,7 +304,7 @@ function testDefaultValue() { )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field->name, 'entity_type' => 'node', 'bundle' => 'date_content', diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeItemTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeItemTest.php index 41a1eb3..e709902 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeItemTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeItemTest.php @@ -35,14 +35,14 @@ public function setUp() { parent::setUp(); // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'name' => 'field_datetime', 'type' => 'datetime', 'entity_type' => 'entity_test', 'settings' => array('datetime_type' => 'date'), )); $this->field->save(); - $this->instance = entity_create('field_instance', array( + $this->instance = entity_create('field_instance_config', array( 'field_name' => $this->field->getName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php b/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php index 2fd63ed..89ae1d9 100644 --- a/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php +++ b/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php @@ -8,6 +8,7 @@ namespace Drupal\edit; use Drupal\Component\Plugin\PluginManagerInterface; +use Drupal\Component\Utility\String; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\edit\Access\EditEntityFieldAccessCheckInterface; @@ -88,7 +89,7 @@ public function generateFieldMetadata(FieldItemListInterface $items, $view_mode) $label = $items->getFieldDefinition()->getLabel(); $editor = $this->editorManager->createInstance($editor_id); $metadata = array( - 'label' => check_plain($label), + 'label' => String::checkPlain($label), 'access' => TRUE, 'editor' => $editor_id, 'aria' => t('Entity @type @id, field @field', array('@type' => $entity->getEntityTypeId(), '@id' => $entity->id(), '@field' => $label)), diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php index 210eabc..e954607 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php @@ -79,7 +79,7 @@ protected function setUp() { )); $this->vocabulary->save(); $this->field_name = 'field_' . $this->vocabulary->id(); - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => $this->field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', @@ -94,7 +94,7 @@ protected function setUp() { ), ), ))->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $this->field_name, 'entity_type' => 'node', 'label' => 'Tags', diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php index b575e6b..e09a127 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php @@ -54,7 +54,7 @@ protected function setUp() { */ public function createFieldWithInstance($field_name, $type, $cardinality, $label, $instance_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings) { $field = $field_name . '_field'; - $this->$field = entity_create('field_entity', array( + $this->$field = entity_create('field_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => $type, @@ -63,7 +63,7 @@ public function createFieldWithInstance($field_name, $type, $cardinality, $label $this->$field->save(); $instance = $field_name . '_instance'; - $this->$instance = entity_create('field_instance', array( + $this->$instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/edit/tests/Drupal/edit/Tests/Access/EditEntityFieldAccessCheckTest.php b/core/modules/edit/tests/Drupal/edit/Tests/Access/EditEntityFieldAccessCheckTest.php index 0791249..cef17cf 100644 --- a/core/modules/edit/tests/Drupal/edit/Tests/Access/EditEntityFieldAccessCheckTest.php +++ b/core/modules/edit/tests/Drupal/edit/Tests/Access/EditEntityFieldAccessCheckTest.php @@ -83,13 +83,13 @@ public function providerTestAccess() { ->method('access') ->will($this->returnValue(FALSE)); - $field_with_access = $this->getMockBuilder('Drupal\field\Entity\Field') + $field_with_access = $this->getMockBuilder('Drupal\field\Entity\FieldConfig') ->disableOriginalConstructor() ->getMock(); $field_with_access->expects($this->any()) ->method('access') ->will($this->returnValue(TRUE)); - $field_without_access = $this->getMockBuilder('Drupal\field\Entity\Field') + $field_without_access = $this->getMockBuilder('Drupal\field\Entity\FieldConfig') ->disableOriginalConstructor() ->getMock(); $field_without_access->expects($this->any()) diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index bad281d..31d5624 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -5,6 +5,7 @@ * Adds bindings for client-side "text editors" to text formats. */ +use Drupal\Component\Utility\Html; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\editor\Entity\Editor; use Drupal\Component\Utility\NestedArray; @@ -592,7 +593,7 @@ function _editor_get_processed_text_fields(ContentEntityInterface $entity) { * An array of all found UUIDs. */ function _editor_parse_file_uuids($text) { - $dom = filter_dom_load($text); + $dom = Html::load($text); $xpath = new \DOMXPath($dom); $uuids = array(); foreach ($xpath->query('//*[@data-editor-file-uuid]') as $node) { diff --git a/core/modules/editor/lib/Drupal/editor/Entity/Editor.php b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php index 27346c9..080b09d 100644 --- a/core/modules/editor/lib/Drupal/editor/Entity/Editor.php +++ b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php @@ -13,12 +13,9 @@ /** * Defines the configured text editor entity. * - * @EntityType( + * @ConfigEntityType( * id = "editor", * label = @Translation("Editor"), - * controllers = { - * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController" - * }, * config_prefix = "editor.editor", * entity_keys = { * "id" = "format", @@ -75,7 +72,7 @@ public function __construct(array $values, $entity_type) { // Initialize settings, merging module-provided defaults. $default_settings = $plugin->getDefaultSettings(); - $default_settings += module_invoke_all('editor_default_settings', $this->editor); + $default_settings += \Drupal::moduleHandler()->invokeAll('editor_default_settings', array($this->editor)); drupal_alter('editor_default_settings', $default_settings, $this->editor); $this->settings += $default_settings; } diff --git a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php index 62973ad..de4f1fc 100644 --- a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php +++ b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php @@ -7,6 +7,7 @@ namespace Drupal\editor\Tests; +use Drupal\Component\Utility\Json; use Drupal\Core\Language\Language; use Drupal\edit\EditorSelector; use Drupal\edit\MetadataGenerator; @@ -199,7 +200,7 @@ public function testGetUntransformedTextCommand() { 'data' => 'Test', ) ); - $this->assertEqual(drupal_json_encode($expected), $response->prepare($request)->getContent(), 'The GetUntransformedTextCommand AJAX command works correctly.'); + $this->assertEqual(Json::encode($expected), $response->prepare($request)->getContent(), 'The GetUntransformedTextCommand AJAX command works correctly.'); } } diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php index 6af964f..9ae6eb0 100644 --- a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php +++ b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php @@ -25,14 +25,14 @@ class EmailFieldTest extends WebTestBase { /** * A field to use in this test class. * - * @var \Drupal\field\Entity\Field + * @var \Drupal\field\Entity\FieldConfig */ protected $field; /** * The instance used in this test class. * - * @var \Drupal\field\Entity\FieldInstance + * @var \Drupal\field\Entity\FieldInstanceConfig */ protected $instance; @@ -61,13 +61,13 @@ function setUp() { function testEmailField() { // Create a field with settings to validate. $field_name = drupal_strtolower($this->randomName()); - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'email', )); $this->field->save(); - $this->instance = entity_create('field_instance', array( + $this->instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php index 1ba03f1..7bbd89b 100644 --- a/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php +++ b/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php @@ -35,12 +35,12 @@ public function setUp() { parent::setUp(); // Create an email field and instance for validation. - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => 'field_email', 'entity_type' => 'entity_test', 'type' => 'email', ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'field_email', 'bundle' => 'entity_test', diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php index 3222af7..7192894 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php @@ -14,12 +14,9 @@ * Configuration entity that contains widget options for all components of a * entity form in a given form mode. * - * @EntityType( + * @ConfigEntityType( * id = "entity_form_display", * label = @Translation("Entity form display"), - * controllers = { - * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController" - * }, * config_prefix = "entity.form_display", * entity_keys = { * "id" = "id", diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php index 43bdad1..38bf22f 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php @@ -27,17 +27,17 @@ * @see entity_get_form_modes() * @see hook_entity_form_mode_info_alter() * - * @EntityType( + * @ConfigEntityType( * id = "form_mode", * label = @Translation("Form mode"), * controllers = { + * "storage" = "Drupal\entity\EntityDisplayModeStorageController", * "list" = "Drupal\entity\EntityFormModeListController", * "form" = { * "add" = "Drupal\entity\Form\EntityFormModeAddForm", * "edit" = "Drupal\entity\Form\EntityDisplayModeEditForm", * "delete" = "Drupal\entity\Form\EntityDisplayModeDeleteForm" - * }, - * "storage" = "Drupal\entity\EntityDisplayModeStorageController" + * } * }, * admin_permission = "administer display modes", * config_prefix = "entity.form_mode", diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityViewDisplay.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityViewDisplay.php index 5ab421e..14f12c4 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityViewDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityViewDisplay.php @@ -16,12 +16,9 @@ * Configuration entity that contains display options for all components of a * rendered entity in a given view mode. * - * @EntityType( + * @ConfigEntityType( * id = "entity_view_display", * label = @Translation("Entity view display"), - * controllers = { - * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController" - * }, * config_prefix = "entity.view_display", * entity_keys = { * "id" = "id", @@ -55,7 +52,7 @@ class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayIn * party code to alter the display options held in the display before they are * used to generate render arrays. * - * @param \Drupal\Core\Entity\EntityInterface[] $entities + * @param \Drupal\Core\Entity\ContentEntityInterface[] $entities * The entities being rendered. They should all be of the same entity type. * @param string $view_mode * The view mode being rendered. @@ -147,7 +144,7 @@ public static function collectRenderDisplays($entities, $view_mode) { * * See the collectRenderDisplays() method for details. * - * @param \Drupal\Core\Entity\EntityInterface $entity + * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity being rendered. * @param string $view_mode * The view mode. @@ -157,7 +154,7 @@ public static function collectRenderDisplays($entities, $view_mode) { * * @see \Drupal\entity\Entity\EntityDisplay::collectRenderDisplays() */ - public static function collectRenderDisplay($entity, $view_mode) { + public static function collectRenderDisplay(ContentEntityInterface $entity, $view_mode) { $displays = static::collectRenderDisplays(array($entity), $view_mode); return $displays[$entity->bundle()]; } diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php index 9a31767..1785888 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php @@ -28,7 +28,7 @@ * @see entity_get_view_modes() * @see hook_entity_view_mode_info_alter() * - * @EntityType( + * @ConfigEntityType( * id = "view_mode", * label = @Translation("View mode"), * controllers = { @@ -37,8 +37,7 @@ * "add" = "Drupal\entity\Form\EntityDisplayModeAddForm", * "edit" = "Drupal\entity\Form\EntityDisplayModeEditForm", * "delete" = "Drupal\entity\Form\EntityDisplayModeDeleteForm" - * }, - * "storage" = "Drupal\entity\EntityDisplayModeStorageController" + * } * }, * admin_permission = "administer display modes", * config_prefix = "entity.view_mode", diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php index f1d84ab..fb31666 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -308,7 +308,7 @@ public function getHighestWeight() { } // Let other modules feedback about their own additions. - $weights = array_merge($weights, module_invoke_all('field_info_max_weight', $this->targetEntityType, $this->bundle, $this->displayContext, $this->mode)); + $weights = array_merge($weights, \Drupal::moduleHandler()->invokeAll('field_info_max_weight', array($this->targetEntityType, $this->bundle, $this->displayContext, $this->mode))); return $weights ? max($weights) : NULL; } diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php index 6131b30..b78131b 100644 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php @@ -136,13 +136,13 @@ public function testFieldComponent() { $field_name = 'test_field'; // Create a field and an instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field' )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -303,13 +303,13 @@ public function testDeleteFieldInstance() { $field_name = 'test_field'; // Create a field and an instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field' )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php index f7f61ba..9dad54d 100644 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php @@ -57,13 +57,13 @@ public function testFieldComponent() { // Create a field and an instance. $field_name = 'test_field'; - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field' )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -185,13 +185,13 @@ public function testDeleteFieldInstance() { $field_name = 'test_field'; // Create a field and an instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field' )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index 7f79580..3c10fee 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -64,11 +64,11 @@ function entity_reference_field_widget_info_alter(&$info) { } /** - * Implements hook_ENTITY_TYPE_update() for 'field_entity'. + * Implements hook_ENTITY_TYPE_update() for 'field_config'. * * Reset the instance handler settings, when the target type is changed. */ -function entity_reference_field_entity_update(FieldInterface $field) { +function entity_reference_field_config_update(FieldInterface $field) { if ($field->type != 'entity_reference') { // Only act on entity reference fields. return; @@ -219,7 +219,7 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f 'target_type' => $target_entity_type, ), ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); } if (empty($instance)) { @@ -233,7 +233,7 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f 'handler_settings' => $selection_handler_settings, ), ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); } } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php index 2e0ad2d..cc883c8 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php @@ -36,7 +36,7 @@ function setUp() { $referenced = $this->drupalCreateContentType(); $this->referenced_type = $referenced->type; - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => 'test_field', 'entity_type' => 'node', 'translatable' => FALSE, @@ -48,7 +48,7 @@ function setUp() { 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'label' => 'Entity reference field', 'field_name' => 'test_field', 'entity_type' => 'node', diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldDefaultValueTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldDefaultValueTest.php index 7d61f3d..9c316a5 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldDefaultValueTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldDefaultValueTest.php @@ -48,14 +48,14 @@ function testEntityReferenceDefaultValue() { // Create a node to be referenced. $referenced_node = $this->drupalCreateNode(array('type' => 'referenced_content')); - $this->field = entity_create('field_entity', array( + $this->field = entity_create('field_config', array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'node', 'type' => 'entity_reference', 'settings' => array('target_type' => 'node'), )); $this->field->save(); - $this->instance = entity_create('field_instance', array( + $this->instance = entity_create('field_instance_config', array( 'field_name' => $this->field->name, 'entity_type' => 'node', 'bundle' => 'reference_content', diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php index 3fb6460..0178a25 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php @@ -61,7 +61,7 @@ protected function assertReferenceable(FieldDefinitionInterface $field_definitio */ public function testNodeHandler() { // Create a field and instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, @@ -73,7 +73,7 @@ public function testNodeHandler() { 'cardinality' => '1', )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_field', 'entity_type' => 'entity_test', 'bundle' => 'test_bundle', @@ -205,7 +205,7 @@ public function testNodeHandler() { */ public function testUserHandler() { // Create a field and instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, @@ -216,7 +216,7 @@ public function testUserHandler() { 'cardinality' => '1', )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_field', 'entity_type' => 'entity_test', 'bundle' => 'test_bundle', @@ -350,7 +350,7 @@ public function testUserHandler() { */ public function testCommentHandler() { // Create a field and instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, @@ -362,7 +362,7 @@ public function testCommentHandler() { 'cardinality' => '1', )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_field', 'entity_type' => 'entity_test', 'bundle' => 'test_bundle', diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php index a93300e..43fd7ee 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php @@ -36,14 +36,14 @@ function setUp() { */ public function testSort() { // Add text field to entity, to sort by. - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => 'field_text', 'entity_type' => 'node', 'type' => 'text', 'entity_types' => array('node'), ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'label' => 'Text Field', 'field_name' => 'field_text', 'entity_type' => 'node', @@ -54,7 +54,7 @@ public function testSort() { // Create a field and instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, @@ -65,7 +65,7 @@ public function testSort() { 'cardinality' => 1, )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_field', 'entity_type' => 'entity_test', 'bundle' => 'test_bundle', diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php index 4c018bb..a8c97cf 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php @@ -40,7 +40,7 @@ public function testSelectionHandler() { } // Create a field and instance. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, @@ -51,7 +51,7 @@ public function testSelectionHandler() { 'cardinality' => '1', )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'test_field', 'entity_type' => 'entity_test', 'bundle' => 'test_bundle', diff --git a/core/modules/entity_reference/tests/modules/entity_reference_test/config/views.view.test_entity_reference.yml b/core/modules/entity_reference/tests/modules/entity_reference_test/config/views.view.test_entity_reference.yml index fbe112a..2bb54bd 100644 --- a/core/modules/entity_reference/tests/modules/entity_reference_test/config/views.view.test_entity_reference.yml +++ b/core/modules/entity_reference/tests/modules/entity_reference_test/config/views.view.test_entity_reference.yml @@ -115,5 +115,4 @@ label: 'Entity reference' module: entity_reference_test id: test_entity_reference tag: '' -uuid: d82ab7cf-088c-485a-9d00-c77876e2fa76 langcode: en diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index e50152b..58f374a 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -318,7 +318,8 @@ function hook_field_formatter_info_alter(array &$info) { * The language the field values are going to be entered in. If no language is * provided the default site language will be used. * - * @deprecated as of Drupal 8.0. Use the entity system instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use the entity system instead, see https://drupal.org/developing/api/entity */ function hook_field_attach_form(\Drupal\Core\Entity\EntityInterface $entity, &$form, &$form_state, $langcode) { // Add a checkbox allowing a given field to be emptied. @@ -346,7 +347,8 @@ function hook_field_attach_form(\Drupal\Core\Entity\EntityInterface $entity, &$f * @param $form_state * An associative array containing the current state of the form. * - * @deprecated as of Drupal 8.0. Use the entity system instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use the entity system instead, see https://drupal.org/developing/api/entity */ function hook_field_attach_extract_form_values(\Drupal\Core\Entity\EntityInterface $entity, $form, &$form_state) { // Sample case of an 'Empty the field' checkbox added on the form, allowing diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index 59c6deb..d613091 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -29,12 +29,12 @@ * The Field Attach API uses the concept of bundles: the set of fields for a * given entity is defined on a per-bundle basis. The collection of bundles for * an entity type is added to the entity definition with - * hook_entity_info_alter(). For instance, node_entity_info_alter() exposes + * hook_entity_type_alter(). For instance, node_entity_type_alter() exposes * each node type as its own bundle. This means that the set of fields of a * node is determined by the node type. * * The Field API reads the bundle name for a given entity from a particular - * property of the entity object, and hook_entity_info_alter() defines which + * property of the entity object, and hook_entity_type_alter() defines which * property to use. For instance, \Drupal\node\Entity\Node specifies: * @code * entity_keys = { diff --git a/core/modules/field/field.deprecated.inc b/core/modules/field/field.deprecated.inc index 6bdc8b2..e74d8bd 100644 --- a/core/modules/field/field.deprecated.inc +++ b/core/modules/field/field.deprecated.inc @@ -35,8 +35,8 @@ * ); * @endcode * - * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getFieldMap(). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\field\Field::fieldInfo()->getFieldMap(). */ function field_info_field_map() { return Field::fieldInfo()->getFieldMap(); @@ -56,9 +56,9 @@ function field_info_field_map() { * entity_load_multiple_by_properties(), NULL if the field was not found. * * @see field_info_field_by_id() - - * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getField($field_name). + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\field\Field::fieldInfo()->getField($field_name). */ function field_info_field($entity_type, $field_name) { return Field::fieldInfo()->getField($entity_type, $field_name); @@ -76,8 +76,8 @@ function field_info_field($entity_type, $field_name) { * * @see field_info_field() * - * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getFieldById($field_id). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\field\Field::fieldInfo()->getFieldById($field_id). */ function field_info_field_by_id($field_id) { return Field::fieldInfo()->getFieldById($field_id); @@ -99,8 +99,8 @@ function field_info_field_by_id($field_id) { * @see field_info_field() * @see field_info_field_by_id() * - * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getFields(). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\field\Field::fieldInfo()->getFields(). */ function field_info_field_by_ids() { return Field::fieldInfo()->getFields(); @@ -131,10 +131,10 @@ function field_info_field_by_ids() { * type, keyed by bundle name. If $entity_type and $bundle_name are set, * return all instances for that bundle. * - * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getInstances(), - * Field::fieldInfo()->getInstances($entity_type) or - * Field::fieldInfo()->getBundleInstances($entity_type, $bundle_name). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. Use + * \Drupal\field\Field::fieldInfo()->getInstances(), + * \Drupal\field\Field::fieldInfo()->getInstances($entity_type) or + * \Drupal\field\Field::fieldInfo()->getBundleInstances($entity_type, $bundle_name). */ function field_info_instances($entity_type = NULL, $bundle_name = NULL) { $cache = Field::fieldInfo(); @@ -168,8 +168,8 @@ function field_info_instances($entity_type = NULL, $bundle_name = NULL) { * An associative array of instance data for the specific field and bundle; * NULL if the instance does not exist. * - * @deprecated as of Drupal 8.0. Use - * Field::fieldInfo()->getInstance($entity_type, $bundle_name, $field_name). + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal\field\Field::fieldInfo()->getInstance($entity_type, $bundle_name, $field_name). */ function field_info_instance($entity_type, $field_name, $bundle_name) { return Field::fieldInfo()->getInstance($entity_type, $bundle_name, $field_name); @@ -273,7 +273,8 @@ function field_info_instance($entity_type, $field_name, $bundle_name) { * An associative array of additional options. See field_invoke_method() for * details. * - * @deprecated as of Drupal 8.0. Use the entity system instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use the entity system instead, see https://drupal.org/developing/api/entity * * @see field_form_get_state() * @see field_form_set_state() @@ -328,7 +329,8 @@ function field_attach_form(EntityInterface $entity, &$form, &$form_state, $langc * An associative array of additional options. See field_invoke_method() for * details. * - * @deprecated as of Drupal 8.0. Use the entity system instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use the entity system instead, see https://drupal.org/developing/api/entity */ function field_attach_form_validate(ContentEntityInterface $entity, $form, &$form_state, array $options = array()) { $has_violations = FALSE; @@ -372,7 +374,8 @@ function field_attach_form_validate(ContentEntityInterface $entity, $form, &$for * An associative array of additional options. See field_invoke_method() for * details. * - * @deprecated as of Drupal 8.0. Use the entity system instead. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use the entity system instead, see https://drupal.org/developing/api/entity */ function field_attach_extract_form_values(EntityInterface $entity, $form, &$form_state, array $options = array()) { // Extract field values from submitted values. diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 6a8b941..6bd2c6d 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -4,6 +4,8 @@ * Attach custom data fields to Drupal entities. */ +use Drupal\Component\Utility\Html; +use Drupal\Component\Utility\Xss; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Template\Attribute; use Drupal\entity\Entity\EntityViewDisplay; @@ -85,7 +87,7 @@ function field_help($path, $arg) { $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Enabling field types') . '
'; - $output .= '
' . t('The Field module provides the infrastructure for fields and field attachment; the field types and input widgets themselves are provided by additional modules. Some of the modules are required; the optional modules can be enabled from the Modules administration page. Drupal core includes the following field type modules: Number (required), Text (required), List (required), Taxonomy (optional), Image (optional), and File (optional); the required Options module provides input widgets for other field modules. Additional fields and widgets may be provided by contributed modules, which you can find in the contributed module section of Drupal.org. Currently enabled field and input widget modules:', array('@modules' => url('admin/modules'), '@contrib' => 'http://drupal.org/project/modules', '@options' => url('admin/help/options'))); + $output .= '
' . t('The Field module provides the infrastructure for fields and field attachment; the field types and input widgets themselves are provided by additional modules. The modules can be enabled from the Modules administration page. Drupal core includes the following field type modules: Text, Number, Email, Link, Telephone, Image, File, Options, Taxonomy, and Entity Reference. Additional fields and widgets may be provided by contributed modules, which you can find in the contributed module section of Drupal.org.', array('@modules' => url('admin/modules'), '@contrib' => 'http://drupal.org/project/modules', '@options' => url('admin/help/options'))); // Make a list of all widget and field modules currently enabled, ordered // by displayed module name (module names are not translated). @@ -93,6 +95,7 @@ function field_help($path, $arg) { $info = system_get_info('module'); $field_widgets = \Drupal::service('plugin.manager.field.widget')->getDefinitions(); $field_types = \Drupal::service('plugin.manager.field.field_type')->getConfigurableDefinitions(); + $providers = array(); foreach (array_merge($field_types, $field_widgets) as $plugin) { $providers[] = $plugin['provider']; } @@ -111,11 +114,14 @@ function field_help($path, $arg) { } } } - $item_list = array( - '#theme' => 'item_list', - '#items' => $items, - ); - $output .= drupal_render($item_list); + if ($items) { + $output .= ' ' . t('Currently enabled field and input widget modules:'); + $item_list = array( + '#theme' => 'item_list', + '#items' => $items, + ); + $output .= drupal_render($item_list); + } return $output; } } @@ -153,7 +159,7 @@ function field_system_info_alter(&$info, $file, $type) { // It is not safe to call entity_load_multiple_by_properties() during // maintenance mode. if ($type == 'module' && !defined('MAINTENANCE_MODE')) { - $fields = entity_load_multiple_by_properties('field_entity', array('module' => $file->name, 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', array('module' => $file->name, 'include_deleted' => TRUE)); if ($fields) { $info['required'] = TRUE; @@ -220,7 +226,7 @@ function field_entity_bundle_create($entity_type, $bundle) { * Implements hook_entity_bundle_rename(). */ function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { - $instances = entity_load_multiple_by_properties('field_instance', array('entity_type' => $entity_type, 'bundle' => $bundle_old)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $entity_type, 'bundle' => $bundle_old)); foreach ($instances as $instance) { if ($instance->entity_type == $entity_type && $instance->bundle == $bundle_old) { $id_new = $instance->entity_type . '.' . $bundle_new . '.' . $instance->field_name; @@ -249,7 +255,7 @@ function field_entity_bundle_delete($entity_type, $bundle) { // Get the instances on the bundle. entity_load_multiple_by_properties() must // be used here since field_info_instances() does not return instances for // disabled entity types or bundles. - $instances = entity_load_multiple_by_properties('field_instance', array('entity_type' => $entity_type, 'bundle' => $bundle)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $entity_type, 'bundle' => $bundle)); foreach ($instances as $instance) { $instance->delete(); } @@ -283,7 +289,7 @@ function field_modules_uninstalled($modules) { * Clears the field info and field data caches. */ function field_cache_clear() { - cache('field')->deleteAll(); + \Drupal::cache('field')->deleteAll(); field_info_cache_clear(); } @@ -304,7 +310,7 @@ function field_cache_clear() { * UTF-8. */ function field_filter_xss($string) { - return _filter_htmlcorrector(filter_xss($string, _field_filter_xss_allowed_tags())); + return Html::normalize(Xss::filter($string, _field_filter_xss_allowed_tags())); } /** diff --git a/core/modules/field/field.purge.inc b/core/modules/field/field.purge.inc index cd8cd04..78b589d 100644 --- a/core/modules/field/field.purge.inc +++ b/core/modules/field/field.purge.inc @@ -5,7 +5,7 @@ * Provides support for field data purge after mass deletion. */ -use Drupal\field\Entity\Field; +use Drupal\field\Entity\FieldConfig; use Drupal\field\FieldException; /** @@ -72,7 +72,7 @@ function field_purge_batch($batch_size) { // Retrieve all deleted field instances. We cannot use field_info_instances() // because that function does not return deleted instances. - $instances = entity_load_multiple_by_properties('field_instance', array('deleted' => TRUE, 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('deleted' => TRUE, 'include_deleted' => TRUE)); $factory = \Drupal::service('entity.query'); $info = \Drupal::entityManager()->getDefinitions(); foreach ($instances as $instance) { @@ -115,7 +115,7 @@ function field_purge_batch($batch_size) { // Retrieve all deleted fields. Any that have no instances can be purged. $deleted_fields = \Drupal::state()->get('field.field.deleted') ?: array(); foreach ($deleted_fields as $field) { - $field = new Field($field); + $field = new FieldConfig($field); // We cannot purge anything if the entity type is unknown (e.g. the // providing module was uninstalled). @@ -124,7 +124,7 @@ function field_purge_batch($batch_size) { continue; } - $instances = entity_load_multiple_by_properties('field_instance', array('field_id' => $field->uuid(), 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid(), 'include_deleted' => TRUE)); if (empty($instances)) { field_purge_field($field); } @@ -163,7 +163,7 @@ function field_purge_instance($instance) { * The field record to purge. */ function field_purge_field($field) { - $instances = entity_load_multiple_by_properties('field_instance', array('field_id' => $field->uuid(), 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid(), 'include_deleted' => TRUE)); if (count($instances) > 0) { throw new FieldException(t('Attempt to purge a field @field_name that still has instances.', array('@field_name' => $field->getName()))); } diff --git a/core/modules/field/lib/Drupal/field/Entity/Field.php b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php similarity index 96% rename from core/modules/field/lib/Drupal/field/Entity/Field.php rename to core/modules/field/lib/Drupal/field/Entity/FieldConfig.php index 69c7551..cef84e5 100644 --- a/core/modules/field/lib/Drupal/field/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\field\Entity\Field. + * Contains \Drupal\field\Entity\FieldConfig. */ namespace Drupal\field\Entity; @@ -18,14 +18,11 @@ /** * Defines the Field entity. * - * @todo use 'field' as the id once hook_field_load() and friends - * are removed. - * - * @EntityType( - * id = "field_entity", + * @ConfigEntityType( + * id = "field_config", * label = @Translation("Field"), * controllers = { - * "storage" = "Drupal\field\FieldStorageController" + * "storage" = "Drupal\field\FieldConfigStorageController" * }, * config_prefix = "field.field", * entity_keys = { @@ -35,7 +32,7 @@ * } * ) */ -class Field extends ConfigEntityBase implements FieldInterface { +class FieldConfig extends ConfigEntityBase implements FieldInterface { /** * The maximum length of the field name, in characters. @@ -185,13 +182,6 @@ class Field extends ConfigEntityBase implements FieldInterface { protected $schema; /** - * The original field. - * - * @var \Drupal\field\Entity\Field - */ - public $original = NULL; - - /** * The data definition of a field item. * * @var \Drupal\Core\TypedData\DataDefinition @@ -199,7 +189,7 @@ class Field extends ConfigEntityBase implements FieldInterface { protected $itemDefinition; /** - * Constructs a Field object. + * Constructs a FieldConfig object. * * @param array $values * An array of field properties, keyed by property name. Most array @@ -212,14 +202,14 @@ class Field extends ConfigEntityBase implements FieldInterface { * - type: required. * * In most cases, Field entities are created via - * entity_create('field_entity', $values)), where $values is the same + * entity_create('field_config', $values)), where $values is the same * parameter as in this constructor. * * @see entity_create() * * @ingroup field_crud */ - public function __construct(array $values, $entity_type = 'field_entity') { + public function __construct(array $values, $entity_type = 'field_config') { // Check required properties. if (empty($values['name'])) { throw new FieldException('Attempt to create an unnamed field.'); @@ -304,8 +294,8 @@ protected function preSaveNew(EntityStorageControllerInterface $storage_controll // Assign the ID. $this->id = $this->id(); - // Field name cannot be longer than Field::NAME_MAX_LENGTH characters. We - // use Unicode::strlen() because the DB layer assumes that column widths + // Field name cannot be longer than FieldConfig::NAME_MAX_LENGTH characters. + // We use Unicode::strlen() because the DB layer assumes that column widths // are given in characters rather than bytes. if (Unicode::strlen($this->name) > static::NAME_MAX_LENGTH) { throw new FieldException(format_string( @@ -386,10 +376,10 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $ */ public static function preDelete(EntityStorageControllerInterface $storage_controller, array $fields) { $state = \Drupal::state(); - $instance_controller = \Drupal::entityManager()->getStorageController('field_instance'); + $instance_controller = \Drupal::entityManager()->getStorageController('field_instance_config'); // Delete instances first. Note: when deleting a field through - // FieldInstance::postDelete(), the instances have been deleted already, so + // FieldInstanceConfig::postDelete(), the instances have been deleted already, so // no instances will be found here. $instance_ids = array(); foreach ($fields as $field) { @@ -563,8 +553,7 @@ public function isTranslatable() { * @param bool $translatable * Whether the field is translatable. * - * @return \Drupal\field\Entity\Field - * The object itself for chaining. + * @return $this */ public function setTranslatable($translatable) { $this->translatable = $translatable; diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php similarity index 96% rename from core/modules/field/lib/Drupal/field/Entity/FieldInstance.php rename to core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index 620e48c..acc01fa 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\field\Entity\FieldInstance. + * Contains \Drupal\field\Entity\FieldInstanceConfig. */ namespace Drupal\field\Entity; @@ -17,11 +17,11 @@ /** * Defines the Field instance entity. * - * @EntityType( - * id = "field_instance", + * @ConfigEntityType( + * id = "field_instance_config", * label = @Translation("Field instance"), * controllers = { - * "storage" = "Drupal\field\FieldInstanceStorageController" + * "storage" = "Drupal\field\FieldInstanceConfigStorageController" * }, * config_prefix = "field.instance", * entity_keys = { @@ -31,7 +31,7 @@ * } * ) */ -class FieldInstance extends ConfigEntityBase implements FieldInstanceInterface { +class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceInterface { /** * The instance ID. @@ -162,9 +162,9 @@ class FieldInstance extends ConfigEntityBase implements FieldInstanceInterface { * The function will be called with the following arguments: * - \Drupal\Core\Entity\EntityInterface $entity * The entity being created. - * - \Drupal\field\Entity\Field $field + * - \Drupal\field\Entity\FieldConfig $field * The field object. - * - \Drupal\field\Entity\FieldInstance $instance + * - \Drupal\field\Entity\FieldInstanceConfig $instance * The field instance object. * - string $langcode * The language of the entity being created. @@ -196,7 +196,7 @@ class FieldInstance extends ConfigEntityBase implements FieldInstanceInterface { /** * The field ConfigEntity object corresponding to $field_uuid. * - * @var \Drupal\field\Entity\Field + * @var \Drupal\field\Entity\FieldConfig */ protected $field; @@ -208,13 +208,6 @@ class FieldInstance extends ConfigEntityBase implements FieldInstanceInterface { protected $bundle_rename_allowed = FALSE; /** - * The original instance. - * - * @var \Drupal\field\Entity\FieldInstance - */ - public $original = NULL; - - /** * The data definition of a field item. * * @var \Drupal\Core\TypedData\DataDefinition @@ -222,7 +215,7 @@ class FieldInstance extends ConfigEntityBase implements FieldInstanceInterface { protected $itemDefinition; /** - * Constructs a FieldInstance object. + * Constructs a FieldInstanceConfig object. * * @param array $values * An array of field instance properties, keyed by property name. Most @@ -238,14 +231,14 @@ class FieldInstance extends ConfigEntityBase implements FieldInstanceInterface { * - bundle: required. * * In most cases, Field instance entities are created via - * entity_create('field_instance', $values), where $values is the same + * entity_create('field_instance_config', $values), where $values is the same * parameter as in this constructor. * * @see entity_create() * * @ingroup field_crud */ - public function __construct(array $values, $entity_type = 'field_instance') { + public function __construct(array $values, $entity_type = 'field_instance_config') { // Field instances configuration is stored with a 'field_uuid' property // unambiguously identifying the field. if (isset($values['field_uuid'])) { @@ -400,7 +393,7 @@ public static function preDelete(EntityStorageControllerInterface $storage_contr * {@inheritdoc} */ public static function postDelete(EntityStorageControllerInterface $storage_controller, array $instances) { - $field_controller = \Drupal::entityManager()->getStorageController('field_entity'); + $field_controller = \Drupal::entityManager()->getStorageController('field_config'); // Clear the cache upfront, to refresh the results of getBundles(). field_cache_clear(); diff --git a/core/modules/field/lib/Drupal/field/FieldStorageController.php b/core/modules/field/lib/Drupal/field/FieldConfigStorageController.php similarity index 96% rename from core/modules/field/lib/Drupal/field/FieldStorageController.php rename to core/modules/field/lib/Drupal/field/FieldConfigStorageController.php index 9c83968..f6d8759 100644 --- a/core/modules/field/lib/Drupal/field/FieldStorageController.php +++ b/core/modules/field/lib/Drupal/field/FieldConfigStorageController.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\field\FieldStorageController. + * Contains \Drupal\field\FieldConfigStorageController. */ namespace Drupal\field; @@ -22,7 +22,7 @@ /** * Controller class for fields. */ -class FieldStorageController extends ConfigStorageController { +class FieldConfigStorageController extends ConfigStorageController { /** * The module handler. @@ -46,7 +46,7 @@ class FieldStorageController extends ConfigStorageController { protected $state; /** - * Constructs a FieldStorageController object. + * Constructs a FieldConfigStorageController object. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 7269567..86db989 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -9,7 +9,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -128,14 +128,14 @@ class FieldInfo { * * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * The cache backend to use. - * @param \Drupal\Core\Config\ConfigFactory $config + * @param \Drupal\Core\Config\ConfigFactoryInterface $config * The configuration factory object to use. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler class to use for invoking hooks. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The 'field type' plugin manager. */ - public function __construct(CacheBackendInterface $cache_backend, ConfigFactory $config, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager) { + public function __construct(CacheBackendInterface $cache_backend, ConfigFactoryInterface $config, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager) { $this->cacheBackend = $cache_backend; $this->moduleHandler = $module_handler; $this->config = $config; @@ -230,7 +230,7 @@ public function getFields() { } else { // Collect and prepare fields. - foreach (entity_load_multiple_by_properties('field_entity', array('include_deleted' => TRUE)) as $field) { + foreach (entity_load_multiple_by_properties('field_config', array('include_deleted' => TRUE)) as $field) { $this->fieldsById[$field->uuid()] = $this->prepareField($field); } @@ -276,7 +276,7 @@ public function getInstances($entity_type = NULL) { // be set by subsequent getBundleInstances() calls. $this->getFields(); - foreach (entity_load_multiple('field_instance') as $instance) { + foreach (entity_load_multiple('field_instance_config') as $instance) { $instance = $this->prepareInstance($instance); $this->bundleInstances[$instance->entity_type][$instance->bundle][$instance->getName()] = $instance; } @@ -322,7 +322,7 @@ public function getField($entity_type, $field_name) { // Do not check the (large) persistent cache, but read the definition. // Cache miss: read from definition. - if ($field = entity_load('field_entity', $entity_type . '.' . $field_name)) { + if ($field = entity_load('field_config', $entity_type . '.' . $field_name)) { $field = $this->prepareField($field); // Save in the "static" cache. @@ -358,7 +358,7 @@ public function getFieldById($field_id) { // bundle. // Cache miss: read from definition. - if ($fields = entity_load_multiple_by_properties('field_entity', array('uuid' => $field_id, 'include_deleted' => TRUE))) { + if ($fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field_id, 'include_deleted' => TRUE))) { $field = current($fields); $field = $this->prepareField($field); @@ -451,7 +451,7 @@ public function getBundleInstances($entity_type, $bundle) { // Load and prepare the corresponding fields and instances entities. if ($config_ids) { // Place the fields in our global "static". - $loaded_fields = entity_load_multiple('field_entity', array_keys($config_ids)); + $loaded_fields = entity_load_multiple('field_config', array_keys($config_ids)); foreach ($loaded_fields as $field) { if (!isset($this->fieldsById[$field->uuid()])) { $field = $this->prepareField($field); @@ -464,7 +464,7 @@ public function getBundleInstances($entity_type, $bundle) { } // Then collect the instances. - $loaded_instances = entity_load_multiple('field_instance', array_values($config_ids)); + $loaded_instances = entity_load_multiple('field_instance_config', array_values($config_ids)); foreach ($loaded_instances as $instance) { $instance = $this->prepareInstance($instance); $instances[$instance->getName()] = $instance; diff --git a/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php b/core/modules/field/lib/Drupal/field/FieldInstanceConfigStorageController.php similarity index 96% rename from core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php rename to core/modules/field/lib/Drupal/field/FieldInstanceConfigStorageController.php index f92e96e..1251b5e 100644 --- a/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php +++ b/core/modules/field/lib/Drupal/field/FieldInstanceConfigStorageController.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\field\FieldInstanceStorageController. + * Contains \Drupal\field\FieldInstanceConfigStorageController. */ namespace Drupal\field; @@ -27,7 +27,7 @@ * (field.field.* entries are processed before field.instance.* entries). * @todo Revisit after http://drupal.org/node/1944368. */ -class FieldInstanceStorageController extends ConfigStorageController { +class FieldInstanceConfigStorageController extends ConfigStorageController { /** * The entity manager. @@ -44,7 +44,7 @@ class FieldInstanceStorageController extends ConfigStorageController { protected $state; /** - * Constructs a FieldInstanceStorageController object. + * Constructs a FieldInstanceConfigStorageController object. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index 6b07808..145fab0 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -113,7 +113,7 @@ function setUp() { } // Create two fields. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'bf_1', 'entity_type' => $this->entity_type, 'type' => 'test_field', @@ -121,7 +121,7 @@ function setUp() { )); $field->save(); $this->fields[] = $field; - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'bf_2', 'entity_type' => $this->entity_type, 'type' => 'test_field', @@ -134,7 +134,7 @@ function setUp() { // entities with values for each field. foreach ($this->bundles as $bundle) { foreach ($this->fields as $field) { - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field->name, 'entity_type' => $this->entity_type, 'bundle' => $bundle, @@ -180,7 +180,7 @@ function testDeleteFieldInstance() { $instance->delete(); // The instance still exists, deleted. - $instances = entity_load_multiple_by_properties('field_instance', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE)); $this->assertEqual(count($instances), 1, 'There is one deleted instance'); $instance = $instances[0]; $this->assertEqual($instance->bundle, $bundle, 'The deleted instance is for the correct bundle'); @@ -247,7 +247,7 @@ function testPurgeInstance() { } // Check hooks invocations. - // hook_field_delete() should have been called once for each entity in the + // FieldItemInterface::delete() should have been called once for each entity in the // bundle. $actual_hooks = field_test_memorize(); $hooks = array(); @@ -258,18 +258,18 @@ function testPurgeInstance() { $this->checkHooksInvocations($hooks, $actual_hooks); // The instance still exists, deleted. - $instances = entity_load_multiple_by_properties('field_instance', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE)); $this->assertEqual(count($instances), 1, 'There is one deleted instance'); // Purge the instance. field_purge_batch($batch_size); // The instance is gone. - $instances = entity_load_multiple_by_properties('field_instance', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE)); + $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE)); $this->assertEqual(count($instances), 0, 'The instance is gone'); // The field still exists, not deleted, because it has a second instance. - $fields = entity_load_multiple_by_properties('field_entity', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); $this->assertTrue(isset($fields[$field->uuid]), 'The field exists and is not deleted'); } @@ -288,7 +288,7 @@ function testPurgeField() { $instance = field_info_instance($this->entity_type, $field->name, $bundle); $instance->delete(); - // Assert that hook_field_delete() was not called yet. + // Assert that FieldItemInterface::delete() was not called yet. $mem = field_test_memorize(); $this->assertEqual(count($mem), 0, 'No field hooks were called.'); @@ -296,7 +296,7 @@ function testPurgeField() { field_purge_batch(10); // Check hooks invocations. - // hook_field_delete() should have been called once for each entity in the + // FieldItemInterface::delete() should have been called once for each entity in the // bundle. $actual_hooks = field_test_memorize(); $hooks = array(); @@ -310,7 +310,7 @@ function testPurgeField() { field_purge_batch(0); // The field still exists, not deleted. - $fields = entity_load_multiple_by_properties('field_entity', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); $this->assertTrue(isset($fields[$field->uuid]) && !$fields[$field->uuid]->deleted, 'The field exists and is not deleted'); // Delete the second instance. @@ -318,7 +318,7 @@ function testPurgeField() { $instance = field_info_instance($this->entity_type, $field->name, $bundle); $instance->delete(); - // Assert that hook_field_delete() was not called yet. + // Assert that FieldItemInterface::delete() was not called yet. $mem = field_test_memorize(); $this->assertEqual(count($mem), 0, 'No field hooks were called.'); @@ -335,14 +335,14 @@ function testPurgeField() { $this->checkHooksInvocations($hooks, $actual_hooks); // The field still exists, deleted. - $fields = entity_load_multiple_by_properties('field_entity', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); $this->assertTrue(isset($fields[$field->uuid]) && $fields[$field->uuid]->deleted, 'The field exists and is deleted'); // Purge again to purge the instance and the field. field_purge_batch(0); // The field is gone. - $fields = entity_load_multiple_by_properties('field_entity', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); $this->assertEqual(count($fields), 0, 'The field is purged.'); } diff --git a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php index e84d9f4..fab8603 100644 --- a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php @@ -42,11 +42,11 @@ function testCreateField() { 'type' => 'test_field', ); field_test_memorize(); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); $mem = field_test_memorize(); - $this->assertIdentical($mem['field_test_field_entity_create'][0][0]->getName(), $field_definition['name'], 'hook_entity_create() called with correct arguments.'); - $this->assertIdentical($mem['field_test_field_entity_create'][0][0]->getType(), $field_definition['type'], 'hook_entity_create() called with correct arguments.'); + $this->assertIdentical($mem['field_test_field_config_create'][0][0]->getName(), $field_definition['name'], 'hook_entity_create() called with correct arguments.'); + $this->assertIdentical($mem['field_test_field_config_create'][0][0]->getType(), $field_definition['type'], 'hook_entity_create() called with correct arguments.'); // Read the configuration. Check against raw configuration data rather than // the loaded ConfigEntity, to be sure we check that the defaults are @@ -68,7 +68,7 @@ function testCreateField() { // Guarantee that the name is unique. try { - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create two fields with the same name.')); } catch (EntityStorageException $e) { @@ -81,7 +81,7 @@ function testCreateField() { 'name' => 'field_1', 'entity_type' => 'entity_type', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create a field with no type.')); } catch (FieldException $e) { @@ -94,7 +94,7 @@ function testCreateField() { 'type' => 'test_field', 'entity_type' => 'entity_test', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create an unnamed field.')); } catch (FieldException $e) { @@ -106,7 +106,7 @@ function testCreateField() { 'name' => 'test_field', 'type' => 'test_field' ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail('Cannot create a field without an entity type.'); } catch (FieldException $e) { @@ -120,7 +120,7 @@ function testCreateField() { 'entity_type' => 'entity_test', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create a field with a name starting with a digit.')); } catch (FieldException $e) { @@ -134,7 +134,7 @@ function testCreateField() { 'entity_type' => 'entity_test', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create a field with a name containing an illegal character.')); } catch (FieldException $e) { @@ -148,7 +148,7 @@ function testCreateField() { 'entity_type' => 'entity_test', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create a field with a name longer than 32 characters.')); } catch (FieldException $e) { @@ -163,7 +163,7 @@ function testCreateField() { 'name' => 'id', 'entity_type' => 'entity_test', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $this->fail(t('Cannot create a field bearing the name of an entity key.')); } catch (FieldException $e) { @@ -186,7 +186,7 @@ function testCreateFieldWithExplicitSchema() { 'dummy' => 'foobar' ), ); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $this->assertEqual($field->getSchema(), $field_definition['schema']); } @@ -199,18 +199,18 @@ function testReadFields() { 'entity_type' => 'entity_test', 'type' => 'test_field', ); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); $id = $field->id(); // Check that 'single column' criteria works. - $fields = entity_load_multiple_by_properties('field_entity', array('field_name' => $field_definition['name'])); + $fields = entity_load_multiple_by_properties('field_config', array('field_name' => $field_definition['name'])); $this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.'); // Check that 'multi column' criteria works. - $fields = entity_load_multiple_by_properties('field_entity', array('field_name' => $field_definition['name'], 'type' => $field_definition['type'])); + $fields = entity_load_multiple_by_properties('field_config', array('field_name' => $field_definition['name'], 'type' => $field_definition['type'])); $this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.'); - $fields = entity_load_multiple_by_properties('field_entity', array('field_name' => $field_definition['name'], 'type' => 'foo')); + $fields = entity_load_multiple_by_properties('field_config', array('field_name' => $field_definition['name'], 'type' => 'foo')); $this->assertTrue(empty($fields), 'No field was found.'); // Create an instance of the field. @@ -219,7 +219,7 @@ function testReadFields() { 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); - entity_create('field_instance', $instance_definition)->save(); + entity_create('field_instance_config', $instance_definition)->save(); } /** @@ -232,10 +232,10 @@ function testFieldIndexes() { 'entity_type' => 'entity_test', 'type' => 'test_field', ); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); field_cache_clear(); - $field = entity_load('field_entity', $field->id()); + $field = entity_load('field_config', $field->id()); $schema = $field->getSchema(); $expected_indexes = array('value' => array('value')); $this->assertEqual($schema['indexes'], $expected_indexes, 'Field type indexes saved by default'); @@ -250,10 +250,10 @@ function testFieldIndexes() { 'value' => array(), ), ); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); field_cache_clear(); - $field = entity_load('field_entity', $field->id()); + $field = entity_load('field_config', $field->id()); $schema = $field->getSchema(); $expected_indexes = array('value' => array()); $this->assertEqual($schema['indexes'], $expected_indexes, 'Field definition indexes override field type indexes'); @@ -268,11 +268,11 @@ function testFieldIndexes() { 'value_2' => array('value'), ), ); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); $id = $field->id(); field_cache_clear(); - $field = entity_load('field_entity', $id); + $field = entity_load('field_config', $id); $schema = $field->getSchema(); $expected_indexes = array('value' => array('value'), 'value_2' => array('value')); $this->assertEqual($schema['indexes'], $expected_indexes, 'Field definition indexes are merged with field type indexes'); @@ -290,13 +290,13 @@ function testDeleteField() { 'type' => 'test_field', 'entity_type' => 'entity_test', ); - entity_create('field_entity', $this->field)->save(); + entity_create('field_config', $this->field)->save(); $this->another_field = array( 'name' => 'field_2', 'type' => 'test_field', 'entity_type' => 'entity_test', ); - entity_create('field_entity', $this->another_field)->save(); + entity_create('field_config', $this->another_field)->save(); // Create instances for each. $this->instance_definition = array( @@ -304,47 +304,47 @@ function testDeleteField() { 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); $another_instance_definition = $this->instance_definition; $another_instance_definition['field_name'] = $this->another_field['name']; - entity_create('field_instance', $another_instance_definition)->save(); + entity_create('field_instance_config', $another_instance_definition)->save(); // Test that the first field is not deleted, and then delete it. - $field = current(entity_load_multiple_by_properties('field_entity', array('field_name' => $this->field['name'], 'include_deleted' => TRUE))); + $field = current(entity_load_multiple_by_properties('field_config', array('field_name' => $this->field['name'], 'include_deleted' => TRUE))); $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.'); field_info_field('entity_test', $this->field['name'])->delete(); // Make sure that the field is marked as deleted when it is specifically // loaded. - $field = current(entity_load_multiple_by_properties('field_entity', array('field_name' => $this->field['name'], 'include_deleted' => TRUE))); + $field = current(entity_load_multiple_by_properties('field_config', array('field_name' => $this->field['name'], 'include_deleted' => TRUE))); $this->assertTrue(!empty($field->deleted), 'A deleted field is marked for deletion.'); // Make sure that this field's instance is marked as deleted when it is // specifically loaded. - $instance = current(entity_load_multiple_by_properties('field_instance', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE))); + $instance = current(entity_load_multiple_by_properties('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE))); $this->assertTrue(!empty($instance->deleted), 'An instance for a deleted field is marked for deletion.'); // Try to load the field normally and make sure it does not show up. - $field = entity_load('field_entity', 'entity_test.' . $this->field['name']); + $field = entity_load('field_config', 'entity_test.' . $this->field['name']); $this->assertTrue(empty($field), 'A deleted field is not loaded by default.'); // Try to load the instance normally and make sure it does not show up. - $instance = entity_load('field_instance', 'entity_test.' . '.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); + $instance = entity_load('field_instance_config', 'entity_test.' . '.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); $this->assertTrue(empty($instance), 'An instance for a deleted field is not loaded by default.'); // Make sure the other field (and its field instance) are not deleted. - $another_field = entity_load('field_entity', 'entity_test.' . $this->another_field['name']); + $another_field = entity_load('field_config', 'entity_test.' . $this->another_field['name']); $this->assertTrue(!empty($another_field) && empty($another_field->deleted), 'A non-deleted field is not marked for deletion.'); - $another_instance = entity_load('field_instance', 'entity_test.' . $another_instance_definition['bundle'] . '.' . $another_instance_definition['field_name']); + $another_instance = entity_load('field_instance_config', 'entity_test.' . $another_instance_definition['bundle'] . '.' . $another_instance_definition['field_name']); $this->assertTrue(!empty($another_instance) && empty($another_instance->deleted), 'An instance of a non-deleted field is not marked for deletion.'); // Try to create a new field the same name as a deleted field and // write data into it. - entity_create('field_entity', $this->field)->save(); - entity_create('field_instance', $this->instance_definition)->save(); - $field = entity_load('field_entity', 'entity_test.' . $this->field['name']); + entity_create('field_config', $this->field)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); + $field = entity_load('field_config', 'entity_test.' . $this->field['name']); $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field with a previously used name is created.'); - $instance = entity_load('field_instance', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name'] ); + $instance = entity_load('field_instance_config', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name'] ); $this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new instance for a previously used field name is created.'); // Save an entity with data for the field @@ -366,7 +366,7 @@ function testUpdateFieldType() { 'entity_type' => 'entity_test', 'type' => 'number_decimal', ); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); try { @@ -387,14 +387,14 @@ function testUpdateField() { // respected. Since cardinality enforcement is consistent across database // systems, it makes a good test case. $cardinality = 4; - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'field_update', 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => $cardinality, )); $field->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => 'field_update', 'entity_type' => 'entity_test', 'bundle' => 'entity_test', @@ -425,7 +425,7 @@ function testUpdateField() { * Test field type modules forbidding an update. */ function testUpdateFieldForbid() { - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'forbidden', 'entity_type' => 'entity_test', 'type' => 'test_field', diff --git a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php index 00ebc40..4fa48cb 100644 --- a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php @@ -97,8 +97,8 @@ function setUp() { ), ); - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $instance)->save(); // Create a display for the default view mode. entity_get_display($instance['entity_type'], $instance['bundle'], 'default') ->setComponent($this->field_name, $this->display_options['default']) diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php index 81eb005..59b0cba 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php @@ -56,13 +56,13 @@ function setUp() { 'entity_type' => 'node', 'type' => 'text', ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => $field['name'], 'entity_type' => 'node', 'bundle' => $content_type, ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); // Assign display properties for the 'default' and 'teaser' view modes. foreach (array('default', 'teaser') as $view_mode) { diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index b4ce690..9428dc0 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -187,14 +187,14 @@ function testFieldAttachCache() { $cid = "field:$entity_type:" . $entity_init->id(); // Check that no initial cache entry is present. - $this->assertFalse(cache('field')->get($cid), 'Non-cached: no initial cache entry'); + $this->assertFalse(\Drupal::cache('field')->get($cid), 'Non-cached: no initial cache entry'); // Save, and check that no cache entry is present. $entity = clone($entity_init); $entity->{$this->field_name}->setValue($values); $entity = $this->entitySaveReload($entity); $cid = "field:$entity_type:" . $entity->id(); - $this->assertFalse(cache('field')->get($cid), 'Non-cached: no cache entry on insert and load'); + $this->assertFalse(\Drupal::cache('field')->get($cid), 'Non-cached: no cache entry on insert and load'); // Cacheable entity type. $entity_type = 'entity_test_cache'; @@ -207,20 +207,20 @@ function testFieldAttachCache() { // Check that no initial cache entry is present. $cid = "field:$entity_type:" . $entity->id(); - $this->assertFalse(cache('field')->get($cid), 'Cached: no initial cache entry'); + $this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no initial cache entry'); // Save, and check that no cache entry is present. $entity = clone($entity_init); $entity->{$this->field_name_2} = $values; $entity->save(); $cid = "field:$entity_type:" . $entity->id(); - $this->assertFalse(cache('field')->get($cid), 'Cached: no cache entry on insert'); + $this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no cache entry on insert'); // Load, and check that a cache entry is present with the expected values. $controller = $this->container->get('entity.manager')->getStorageController($entity->getEntityTypeId()); $controller->resetCache(); $controller->load($entity->id()); - $cache = cache('field')->get($cid); + $cache = \Drupal::cache('field')->get($cid); $this->assertEqual($cache->data[$langcode][$this->field_name_2], $values, 'Cached: correct cache entry on load'); // Update with different values, and check that the cache entry is wiped. @@ -231,12 +231,12 @@ function testFieldAttachCache() { )); $entity->{$this->field_name_2} = $values; $entity->save(); - $this->assertFalse(cache('field')->get($cid), 'Cached: no cache entry on update'); + $this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no cache entry on update'); // Load, and check that a cache entry is present with the expected values. $controller->resetCache(); $controller->load($entity->id()); - $cache = cache('field')->get($cid); + $cache = \Drupal::cache('field')->get($cid); $this->assertEqual($cache->data[$langcode][$this->field_name_2], $values, 'Cached: correct cache entry on load'); // Create a new revision, and check that the cache entry is wiped. @@ -248,17 +248,17 @@ function testFieldAttachCache() { $entity->{$this->field_name_2} = $values; $entity->setNewRevision(); $entity->save(); - $this->assertFalse(cache('field')->get($cid), 'Cached: no cache entry on new revision creation'); + $this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no cache entry on new revision creation'); // Load, and check that a cache entry is present with the expected values. $controller->resetCache(); $controller->load($entity->id()); - $cache = cache('field')->get($cid); + $cache = \Drupal::cache('field')->get($cid); $this->assertEqual($cache->data[$langcode][$this->field_name_2], $values, 'Cached: correct cache entry on load'); // Delete, and check that the cache entry is wiped. $entity->delete(); - $this->assertFalse(cache('field')->get($cid), 'Cached: no cache entry after delete'); + $this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no cache entry after delete'); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php index 27e1c6d..a981a18 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -15,7 +15,7 @@ class FieldAttachStorageTest extends FieldUnitTestBase { /** * The field instance. * - * @var \Drupal\field\Entity\FieldInstance + * @var \Drupal\field\Entity\FieldInstanceConfig */ protected $instance; @@ -121,7 +121,7 @@ function testFieldAttachLoadMultiple() { ); for ($i = 1; $i <= 3; $i++) { $field_names[$i] = 'field_' . $i; - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => $field_names[$i], 'entity_type' => $entity_type, 'type' => 'test_field', @@ -129,7 +129,7 @@ function testFieldAttachLoadMultiple() { $field->save(); $field_ids[$i] = $field->uuid(); foreach ($field_bundles_map[$i] as $bundle) { - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field_names[$i], 'entity_type' => $entity_type, 'bundle' => $bundles[$bundle], @@ -314,7 +314,7 @@ function testEntityCreateRenameBundle() { // Add an instance to that bundle. $this->instance_definition['bundle'] = $new_bundle; - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); // Save an entity with data in the field. $entity = entity_create($entity_type, array('type' => $this->instance->bundle)); @@ -353,7 +353,7 @@ function testEntityDeleteBundle() { // Add an instance to that bundle. $this->instance_definition['bundle'] = $new_bundle; - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); // Create a second field for the test bundle $field_name = drupal_strtolower($this->randomName() . '_field_name'); @@ -363,7 +363,7 @@ function testEntityDeleteBundle() { 'type' => 'test_field', 'cardinality' => 1, ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => $field_name, 'entity_type' => $entity_type, @@ -372,7 +372,7 @@ function testEntityDeleteBundle() { 'description' => $this->randomName() . '_description', 'weight' => mt_rand(0, 127), ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); // Save an entity with data for both fields $entity = entity_create($entity_type, array('type' => $this->instance->bundle)); @@ -397,8 +397,8 @@ function testEntityDeleteBundle() { $this->assertTrue(empty($entity->{$field_name}), 'No data for second field'); // Verify that the instances are gone. - $this->assertFalse(entity_load('field_instance', 'entity_test.' . $this->instance->bundle . '.' . $this->field_name), "First field is deleted"); - $this->assertFalse(entity_load('field_instance', 'entity_test.' . $instance['bundle']. '.' . $field_name), "Second field is deleted"); + $this->assertFalse(entity_load('field_instance_config', 'entity_test.' . $this->instance->bundle . '.' . $this->field_name), "First field is deleted"); + $this->assertFalse(entity_load('field_instance_config', 'entity_test.' . $instance['bundle']. '.' . $field_name), "Second field is deleted"); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php index f7e001f..d5d6407 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php @@ -51,7 +51,7 @@ function testImportChange() { $this->configImporter()->import(); // Check that the updated config was correctly imported. - $instance = entity_load('field_instance', $instance_id); + $instance = entity_load('field_instance_config', $instance_id); $this->assertEqual($instance->getLabel(), $new_label, 'Instance label updated'); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php index 2461165..f248fdc 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php @@ -35,11 +35,11 @@ function testImportCreateDefault() { $instance_id_2b = "entity_test.test_bundle.$field_name_2"; // Check that the fields and instances do not exist yet. - $this->assertFalse(entity_load('field_entity', $field_id)); - $this->assertFalse(entity_load('field_instance', $instance_id)); - $this->assertFalse(entity_load('field_entity', $field_id_2)); - $this->assertFalse(entity_load('field_instance', $instance_id_2a)); - $this->assertFalse(entity_load('field_instance', $instance_id_2b)); + $this->assertFalse(entity_load('field_config', $field_id)); + $this->assertFalse(entity_load('field_instance_config', $instance_id)); + $this->assertFalse(entity_load('field_config', $field_id_2)); + $this->assertFalse(entity_load('field_instance_config', $instance_id_2a)); + $this->assertFalse(entity_load('field_instance_config', $instance_id_2b)); // Create a second bundle for the 'Entity test' entity type. entity_test_create_bundle('test_bundle'); @@ -49,13 +49,13 @@ function testImportCreateDefault() { \Drupal::moduleHandler()->install(array('field_test_config')); // A field with one instance. - $field = entity_load('field_entity', $field_id); + $field = entity_load('field_config', $field_id); $this->assertTrue($field, 'The field was created.'); - $instance = entity_load('field_instance', $instance_id); + $instance = entity_load('field_instance_config', $instance_id); $this->assertTrue($instance, 'The field instance was deleted.'); // A field with multiple instances. - $field_2 = entity_load('field_entity', $field_id_2); + $field_2 = entity_load('field_config', $field_id_2); $this->assertTrue($field_2, 'The second field was created.'); $this->assertTrue($instance->bundle, 'test_bundle', 'The second field instance was created on bundle test_bundle.'); $this->assertTrue($instance->bundle, 'test_bundle_2', 'The second field instance was created on bundle test_bundle_2.'); @@ -106,15 +106,15 @@ function testImportCreate() { $this->configImporter()->import(); // Check that the field and instance were created. - $field = entity_load('field_entity', $field_id); + $field = entity_load('field_config', $field_id); $this->assertTrue($field, 'Test import field from staging exists'); - $instance = entity_load('field_instance', $instance_id); + $instance = entity_load('field_instance_config', $instance_id); $this->assertTrue($instance, 'Test import field instance from staging exists'); - $field = entity_load('field_entity', $field_id_2); + $field = entity_load('field_config', $field_id_2); $this->assertTrue($field, 'Test import field 2 from staging exists'); - $instance = entity_load('field_instance', $instance_id_2a); + $instance = entity_load('field_instance_config', $instance_id_2a); $this->assertTrue($instance, 'Test import field instance 2a from staging exists'); - $instance = entity_load('field_instance', $instance_id_2b); + $instance = entity_load('field_instance_config', $instance_id_2b); $this->assertTrue($instance, 'Test import field instance 2b from staging exists'); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php index 23ae199..d2388f7 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php @@ -51,8 +51,8 @@ public function testImportDelete() { $this->installConfig(array('field_test_config')); // Get the uuid's for the fields. - $field_uuid = entity_load('field_entity', $field_id)->uuid(); - $field_uuid_2 = entity_load('field_entity', $field_id_2)->uuid(); + $field_uuid = entity_load('field_config', $field_id)->uuid(); + $field_uuid_2 = entity_load('field_config', $field_id_2)->uuid(); $active = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); @@ -67,15 +67,15 @@ public function testImportDelete() { $this->configImporter()->import(); // Check that the fields and instances are gone. - $field = entity_load('field_entity', $field_id, TRUE); + $field = entity_load('field_config', $field_id, TRUE); $this->assertFalse($field, 'The field was deleted.'); - $field_2 = entity_load('field_entity', $field_id_2, TRUE); + $field_2 = entity_load('field_config', $field_id_2, TRUE); $this->assertFalse($field_2, 'The second field was deleted.'); - $instance = entity_load('field_instance', $instance_id, TRUE); + $instance = entity_load('field_instance_config', $instance_id, TRUE); $this->assertFalse($instance, 'The field instance was deleted.'); - $instance_2a = entity_load('field_instance', $instance_id_2a, TRUE); + $instance_2a = entity_load('field_instance_config', $instance_id_2a, TRUE); $this->assertFalse($instance_2a, 'The second field instance on test bundle was deleted.'); - $instance_2b = entity_load('field_instance', $instance_id_2b, TRUE); + $instance_2b = entity_load('field_instance_config', $instance_id_2b, TRUE); $this->assertFalse($instance_2b, 'The second field instance on test bundle 2 was deleted.'); // Check that all config files are gone. diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php index 8b67798..32ffe10 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php @@ -41,7 +41,7 @@ function testFieldInfo() { // Create a field, verify it shows up. $core_fields = field_info_fields(); - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => drupal_strtolower($this->randomName()), 'entity_type' => 'entity_test', 'type' => 'test_field', @@ -67,7 +67,7 @@ function testFieldInfo() { 'description' => $this->randomName(), 'weight' => mt_rand(0, 127), ); - $instance = entity_create('field_instance', $instance_definition); + $instance = entity_create('field_instance_config', $instance_definition); $instance->save(); $entity_type = \Drupal::entityManager()->getDefinition('entity_test'); @@ -116,7 +116,7 @@ function testFieldPrepare() { 'entity_type' => 'entity_test', 'type' => 'test_field', ); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); // Simulate a stored field definition missing a field setting (e.g. a @@ -144,13 +144,13 @@ function testInstancePrepare() { 'entity_type' => 'entity_test', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $instance_definition = array( 'field_name' => $field_definition['name'], 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); - $instance = entity_create('field_instance', $instance_definition); + $instance = entity_create('field_instance_config', $instance_definition); $instance->save(); // Simulate a stored instance definition missing various settings (e.g. a @@ -186,13 +186,13 @@ function testInstanceDisabledEntityType() { 'entity_type' => 'comment', 'type' => 'test_field', ); - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $instance_definition = array( 'field_name' => 'field', 'entity_type' => 'comment', 'bundle' => 'comment_node_article', ); - entity_create('field_instance', $instance_definition)->save(); + entity_create('field_instance_config', $instance_definition)->save(); $this->assertNotNull(field_info_instance('comment', 'field', 'comment_node_article'), 'Instance is returned on enabled entity types.'); // Disable comment module. This clears field_info cache. @@ -229,7 +229,7 @@ function testFieldMap() { ), ); foreach ($fields as $field) { - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); } // Create a couple instances. @@ -256,7 +256,7 @@ function testFieldMap() { ), ); foreach ($instances as $instance) { - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); } $expected = array( @@ -303,7 +303,7 @@ function testFieldInfoCache() { // Create a test field and ensure it's in the array returned by // field_info_fields(). $field_name = drupal_strtolower($this->randomName()); - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field', @@ -314,10 +314,10 @@ function testFieldInfoCache() { // Now rebuild the field info cache, and set a variable which will cause // the cache to be cleared while it's being rebuilt; see - // field_test_entity_info(). Ensure the test field is still in the returned + // field_test_entity_type_build(). Ensure the test field is still in the returned // array. field_info_cache_clear(); - \Drupal::state()->set('field_test.clear_info_cache_in_hook_entity_info', TRUE); + \Drupal::state()->set('field_test.clear_info_cache_in_hook_entity_type_build', TRUE); $fields = field_info_fields(); $this->assertTrue(isset($fields[$field->uuid]), 'The test field is found in the array returned by field_info_fields() even if its cache is cleared while being rebuilt.'); } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php index 9eaa8d0..1f73528 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php @@ -15,7 +15,7 @@ class FieldInstanceCrudTest extends FieldUnitTestBase { /** * The field entity. * - * @var \Drupal\field\Entity\Field + * @var \Drupal\field\Entity\FieldConfig */ protected $field; @@ -49,7 +49,7 @@ function setUp() { 'entity_type' => 'entity_test', 'type' => 'test_field', ); - $this->field = entity_create('field_entity', $this->field_definition); + $this->field = entity_create('field_config', $this->field_definition); $this->field->save(); $this->instance_definition = array( 'field_name' => $this->field->getName(), @@ -68,7 +68,7 @@ function setUp() { * Test the creation of a field instance. */ function testCreateFieldInstance() { - $instance = entity_create('field_instance', $this->instance_definition); + $instance = entity_create('field_instance_config', $this->instance_definition); $instance->save(); // Read the configuration. Check against raw configuration data rather than @@ -88,7 +88,7 @@ function testCreateFieldInstance() { // Guarantee that the field/bundle combination is unique. try { - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); $this->fail(t('Cannot create two instances with the same field / bundle combination.')); } catch (EntityStorageException $e) { @@ -98,7 +98,7 @@ function testCreateFieldInstance() { // Check that the specified field exists. try { $this->instance_definition['field_name'] = $this->randomName(); - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); $this->fail(t('Cannot create an instance of a non-existing field.')); } catch (FieldException $e) { @@ -112,10 +112,10 @@ function testCreateFieldInstance() { * Test reading back an instance definition. */ function testReadFieldInstance() { - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); // Read the instance back. - $instance = entity_load('field_instance', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); + $instance = entity_load('field_instance_config', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); $this->assertTrue($this->instance_definition['field_name'] == $instance->getName(), 'The field was properly read.'); $this->assertTrue($this->instance_definition['entity_type'] == $instance->entity_type, 'The field was properly read.'); $this->assertTrue($this->instance_definition['bundle'] == $instance->bundle, 'The field was properly read.'); @@ -125,17 +125,17 @@ function testReadFieldInstance() { * Test the update of a field instance. */ function testUpdateFieldInstance() { - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); // Check that basic changes are saved. - $instance = entity_load('field_instance', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); + $instance = entity_load('field_instance_config', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); $instance->required = !$instance->isRequired(); $instance->label = $this->randomName(); $instance->description = $this->randomName(); $instance->settings['test_instance_setting'] = $this->randomName(); $instance->save(); - $instance_new = entity_load('field_instance', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); + $instance_new = entity_load('field_instance_config', 'entity_test.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); $this->assertEqual($instance->isRequired(), $instance_new->isRequired(), '"required" change is saved'); $this->assertEqual($instance->getLabel(), $instance_new->getLabel(), '"label" change is saved'); $this->assertEqual($instance->getDescription(), $instance_new->getDescription(), '"description" change is saved'); @@ -153,27 +153,27 @@ function testDeleteFieldInstance() { // Create two instances for the same field so we can test that only one // is deleted. - entity_create('field_instance', $this->instance_definition)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); $another_instance_definition = $this->instance_definition; $another_instance_definition['bundle'] .= '_another_bundle'; - entity_create('field_instance', $another_instance_definition)->save(); + entity_create('field_instance_config', $another_instance_definition)->save(); // Test that the first instance is not deleted, and then delete it. - $instance = current(entity_load_multiple_by_properties('field_instance', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE))); + $instance = current(entity_load_multiple_by_properties('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE))); $this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new field instance is not marked for deletion.'); $instance->delete(); // Make sure the instance is marked as deleted when the instance is // specifically loaded. - $instance = current(entity_load_multiple_by_properties('field_instance', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE))); + $instance = current(entity_load_multiple_by_properties('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => $this->instance_definition['field_name'], 'bundle' => $this->instance_definition['bundle'], 'include_deleted' => TRUE))); $this->assertTrue(!empty($instance->deleted), 'A deleted field instance is marked for deletion.'); // Try to load the instance normally and make sure it does not show up. - $instance = entity_load('field_instance', 'entity_test.' . '.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); + $instance = entity_load('field_instance_config', 'entity_test.' . '.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); $this->assertTrue(empty($instance), 'A deleted field instance is not loaded by default.'); // Make sure the other field instance is not deleted. - $another_instance = entity_load('field_instance', 'entity_test.' . $another_instance_definition['bundle'] . '.' . $another_instance_definition['field_name']); + $another_instance = entity_load('field_instance_config', 'entity_test.' . $another_instance_definition['bundle'] . '.' . $another_instance_definition['field_name']); $this->assertTrue(!empty($another_instance) && empty($another_instance->deleted), 'A non-deleted field instance is not marked for deletion.'); } @@ -186,18 +186,18 @@ function testDeleteFieldInstanceCrossDeletion() { // Check that deletion of a field deletes its instances. $field = $this->field; - entity_create('field_instance', $this->instance_definition)->save(); - entity_create('field_instance', $instance_definition_2)->save(); + entity_create('field_instance_config', $this->instance_definition)->save(); + entity_create('field_instance_config', $instance_definition_2)->save(); $field->delete(); $this->assertFalse(field_info_instance('entity_test', $this->instance_definition['bundle'], $field->name)); $this->assertFalse(field_info_instance('entity_test', $instance_definition_2['bundle'], $field->name)); // Chack that deletion of the last instance deletes the field. - $field = entity_create('field_entity', $this->field_definition); + $field = entity_create('field_config', $this->field_definition); $field->save(); - $instance = entity_create('field_instance', $this->instance_definition); + $instance = entity_create('field_instance_config', $this->instance_definition); $instance->save(); - $instance_2 = entity_create('field_instance', $instance_definition_2); + $instance_2 = entity_create('field_instance_config', $instance_definition_2); $instance_2->save(); $instance->delete(); $this->assertTrue(field_info_field('entity_test', $field->name)); @@ -206,13 +206,13 @@ function testDeleteFieldInstanceCrossDeletion() { // Check that deletion of all instances of the same field simultaneously // deletes the field. - $field = entity_create('field_entity', $this->field_definition); + $field = entity_create('field_config', $this->field_definition); $field->save(); - $instance = entity_create('field_instance', $this->instance_definition); + $instance = entity_create('field_instance_config', $this->instance_definition); $instance->save(); - $instance_2 = entity_create('field_instance', $instance_definition_2); + $instance_2 = entity_create('field_instance_config', $instance_definition_2); $instance_2->save(); - $instance_controller = $this->container->get('entity.manager')->getStorageController('field_instance'); + $instance_controller = $this->container->get('entity.manager')->getStorageController('field_instance_config'); $instance_controller->delete(array($instance, $instance_2)); $this->assertFalse(field_info_field('entity_test', $field->name)); } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php index b27e88e..9e10afd 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -67,7 +67,7 @@ function createFieldWithInstance($suffix = '', $entity_type = 'entity_test', $bu $instance_definition = 'instance_definition' . $suffix; $this->$field_name = drupal_strtolower($this->randomName() . '_field_name' . $suffix); - $this->$field = entity_create('field_entity', array( + $this->$field = entity_create('field_config', array( 'name' => $this->$field_name, 'entity_type' => $entity_type, 'type' => 'test_field', @@ -85,7 +85,7 @@ function createFieldWithInstance($suffix = '', $entity_type = 'entity_test', $bu 'test_instance_setting' => $this->randomName(), ), ); - $this->$instance = entity_create('field_instance', $this->$instance_definition); + $this->$instance = entity_create('field_instance_config', $this->$instance_definition); $this->$instance->save(); entity_get_form_display($entity_type, $bundle, 'default') diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index 81ec2ff..5de1d0a 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -94,8 +94,8 @@ function testFieldFormSingle() { $field = $this->field_single; $field_name = $field['name']; $this->instance['field_name'] = $field_name; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -178,8 +178,8 @@ function testFieldFormDefaultValue() { $this->instance['field_name'] = $field_name; $default = rand(1, 127); $this->instance['default_value'] = array(array('value' => $default)); - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -208,8 +208,8 @@ function testFieldFormSingleRequired() { $field_name = $field['name']; $this->instance['field_name'] = $field_name; $this->instance['required'] = TRUE; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -248,16 +248,16 @@ function testFieldFormSingleRequired() { // $this->field = $this->field_multiple; // $field_name = $this->field['field_name']; // $this->instance['field_name'] = $field_name; -// entity_create('field_entity', $this->field)->save(); -// entity_create('field_instance', $this->instance)->save(); +// entity_create('field_config', $this->field)->save(); +// entity_create('field_instance_config', $this->instance)->save(); // } function testFieldFormUnlimited() { $field = $this->field_unlimited; $field_name = $field['name']; $this->instance['field_name'] = $field_name; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -342,14 +342,14 @@ function testFieldFormMultivalueWithRequiredRadio() { $field = $this->field_unlimited; $field_name = $field['name']; $this->instance['field_name'] = $field_name; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); // Add a required radio field. - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => 'required_radio_test', 'entity_type' => 'entity_test', 'type' => 'list_text', @@ -363,7 +363,7 @@ function testFieldFormMultivalueWithRequiredRadio() { 'bundle' => 'entity_test', 'required' => TRUE, ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default') ->setComponent($instance['field_name'], array( 'type' => 'options_buttons', @@ -389,8 +389,8 @@ function testFieldFormJSAddMore() { $field = $this->field_unlimited; $field_name = $field['name']; $this->instance['field_name'] = $field_name; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name) ->save(); @@ -450,8 +450,8 @@ function testFieldFormMultipleWidget() { $field = $this->field_multiple; $field_name = $field['name']; $this->instance['field_name'] = $field_name; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $this->instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($field_name, array( 'type' => 'test_field_widget_multiple', @@ -501,8 +501,8 @@ function testFieldFormAccess() { $instance['field_name'] = $field_name; $instance['entity_type'] = $entity_type; $instance['bundle'] = $entity_type; - entity_create('field_entity', $field)->save(); - entity_create('field_instance', $instance)->save(); + entity_create('field_config', $field)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display($entity_type, $entity_type, 'default') ->setComponent($field_name) ->save(); @@ -521,8 +521,8 @@ function testFieldFormAccess() { 'bundle' => $entity_type, 'default_value' => array(0 => array('value' => 99)), ); - entity_create('field_entity', $field_no_access)->save(); - entity_create('field_instance', $instance_no_access)->save(); + entity_create('field_config', $field_no_access)->save(); + entity_create('field_instance_config', $instance_no_access)->save(); entity_get_form_display($instance_no_access['entity_type'], $instance_no_access['bundle'], 'default') ->setComponent($field_name_no_access) ->save(); @@ -591,8 +591,8 @@ function testHiddenField() { $this->instance['default_value'] = array(0 => array('value' => 99)); $this->instance['entity_type'] = $entity_type; $this->instance['bundle'] = $entity_type; - entity_create('field_entity', $field)->save(); - $this->instance = entity_create('field_instance', $this->instance); + entity_create('field_config', $field)->save(); + $this->instance = entity_create('field_instance_config', $this->instance); $this->instance->save(); // We explicitly do not assign a widget in a form display, so the field // stays hidden in forms. diff --git a/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php b/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php index 5da9ec0..d120b95 100644 --- a/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php @@ -61,17 +61,17 @@ public function setUp() { */ function testNestedFieldForm() { // Add two instances on the 'entity_test' - entity_create('field_entity', $this->field_single)->save(); - entity_create('field_entity', $this->field_unlimited)->save(); + entity_create('field_config', $this->field_single)->save(); + entity_create('field_config', $this->field_unlimited)->save(); $this->instance['field_name'] = 'field_single'; $this->instance['label'] = 'Single field'; - entity_create('field_instance', $this->instance)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->instance['field_name']) ->save(); $this->instance['field_name'] = 'field_unlimited'; $this->instance['label'] = 'Unlimited field'; - entity_create('field_instance', $this->instance)->save(); + entity_create('field_instance_config', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') ->setComponent($this->instance['field_name']) ->save(); diff --git a/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php b/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php index 36a3d52..d3afd9a 100644 --- a/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php @@ -46,13 +46,13 @@ public function setUp() { 'entity_type' => 'entity_test', 'type' => 'shape', ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'entity_type' => 'entity_test', 'field_name' => $this->field_name, 'bundle' => 'entity_test', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php b/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php index 5d8d9f8..f48c48c 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TestItemTest.php @@ -47,13 +47,13 @@ public function setUp() { 'entity_type' => 'entity_test', 'type' => 'test_field', ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'entity_type' => 'entity_test', 'field_name' => $this->field_name, 'bundle' => 'entity_test', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php index 8f5a4b1..02630bb 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php @@ -57,14 +57,14 @@ class TranslationTest extends FieldUnitTestBase { /** * The field to use in this test. * - * @var \Drupal\field\Entity\Field + * @var \Drupal\field\Entity\FieldConfig */ protected $field; /** * The field instance to use in this test. * - * @var \Drupal\field\Entity\FieldInstance + * @var \Drupal\field\Entity\FieldInstanceConfig */ protected $instance; @@ -92,7 +92,7 @@ function setUp() { 'cardinality' => 4, 'translatable' => TRUE, ); - $this->field = entity_create('field_entity', $this->field_definition); + $this->field = entity_create('field_config', $this->field_definition); $this->field->save(); $this->instance_definition = array( @@ -100,7 +100,7 @@ function setUp() { 'entity_type' => $this->entity_type, 'bundle' => 'entity_test', ); - $this->instance = entity_create('field_instance', $this->instance_definition); + $this->instance = entity_create('field_instance_config', $this->instance_definition); $this->instance->save(); for ($i = 0; $i < 3; ++$i) { @@ -149,12 +149,12 @@ function testTranslatableFieldSaveLoad() { $field_name_default = drupal_strtolower($this->randomName() . '_field_name'); $field_definition = $this->field_definition; $field_definition['name'] = $field_name_default; - entity_create('field_entity', $field_definition)->save(); + entity_create('field_config', $field_definition)->save(); $instance_definition = $this->instance_definition; $instance_definition['field_name'] = $field_name_default; $instance_definition['default_value'] = array(array('value' => rand(1, 127))); - $instance = entity_create('field_instance', $instance_definition); + $instance = entity_create('field_instance_config', $instance_definition); $instance->save(); entity_info_cache_clear(); diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php index 03f6e7e..d8d9f9c 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php @@ -38,14 +38,14 @@ class TranslationWebTest extends FieldTestBase { /** * The field to use in this test. * - * @var \Drupal\field\Entity\Field + * @var \Drupal\field\Entity\FieldConfig */ protected $field; /** * The field instance to use in this test. * - * @var \Drupal\field\Entity\FieldInstance + * @var \Drupal\field\Entity\FieldInstanceConfig */ protected $instance; @@ -69,16 +69,16 @@ function setUp() { 'cardinality' => 4, 'translatable' => TRUE, ); - entity_create('field_entity', $field)->save(); - $this->field = entity_load('field_entity', $this->entity_type . '.' . $this->field_name); + entity_create('field_config', $field)->save(); + $this->field = entity_load('field_config', $this->entity_type . '.' . $this->field_name); $instance = array( 'field_name' => $this->field_name, 'entity_type' => $this->entity_type, 'bundle' => $this->entity_type, ); - entity_create('field_instance', $instance)->save(); - $this->instance = entity_load('field_instance', 'entity_test.' . $instance['bundle'] . '.' . $this->field_name); + entity_create('field_instance_config', $instance)->save(); + $this->instance = entity_load('field_instance_config', 'entity_test.' . $instance['bundle'] . '.' . $this->field_name); entity_get_form_display($this->entity_type, $this->entity_type, 'default') ->setComponent($this->field_name) diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/ApiDataTest.php b/core/modules/field/lib/Drupal/field/Tests/Views/ApiDataTest.php index 3e6bbe6..be84f86 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/ApiDataTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/ApiDataTest.php @@ -37,7 +37,7 @@ function setUp() { 'entity_type' => 'node', 'bundle' => 'page', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); // Now create some example nodes/users for the view result. for ($i = 0; $i < 5; $i++) { diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php b/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php index 7badfb6..c65e95b 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php @@ -66,7 +66,7 @@ function setUpFields($amount = 3) { 'type' => 'text', ); - $this->fields[$i] = $field = entity_create('field_entity', $field); + $this->fields[$i] = $field = entity_create('field_config', $field); $field->save(); } return $field_names; @@ -79,7 +79,7 @@ function setUpInstances($bundle = 'page') { 'entity_type' => 'node', 'bundle' => 'page', ); - $this->instances[$key] = entity_create('field_instance', $instance); + $this->instances[$key] = entity_create('field_instance_config', $instance); $this->instances[$key]->save(); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php index 850edc1..b14d24d 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php @@ -48,7 +48,7 @@ protected function setUp() { $this->setUpFields(3); // Setup a field with cardinality > 1. - $this->fields[3] = $field = entity_create('field_entity', array( + $this->fields[3] = $field = entity_create('field_config', array( 'name' => 'field_name_3', 'entity_type' => 'node', 'type' => 'text', @@ -56,7 +56,7 @@ protected function setUp() { )); $field->save(); // Setup a field that will have no value. - $this->fields[4] = $field = entity_create('field_entity', array( + $this->fields[4] = $field = entity_create('field_config', array( 'name' => 'field_name_4', 'entity_type' => 'node', 'type' => 'text', diff --git a/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php b/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php index 87e2347..5702719 100644 --- a/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php @@ -49,13 +49,13 @@ function setUp() { function testReEnabledField() { // Add a telephone field to the article content type. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => 'field_telephone', 'entity_type' => 'node', 'type' => 'telephone', )); $field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => 'field_telephone', 'label' => 'Telephone Number', 'entity_type' => 'node', diff --git a/core/modules/field/tests/modules/field_test/field_test.entity.inc b/core/modules/field/tests/modules/field_test/field_test.entity.inc index af13590..2d6a96b 100644 --- a/core/modules/field/tests/modules/field_test/field_test.entity.inc +++ b/core/modules/field/tests/modules/field_test/field_test.entity.inc @@ -7,24 +7,24 @@ */ /** - * Implements hook_entity_info(). + * Implements hook_entity_type_build(). */ -function field_test_entity_info() { +function field_test_entity_type_build() { /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ // If requested, clear the field cache while this is being called. See // Drupal\field\Tests\FieldInfoTest::testFieldInfoCache(). - if (\Drupal::state()->get('field_test.clear_info_cache_in_hook_entity_info')) { + if (\Drupal::state()->get('field_test.clear_info_cache_in_hook_entity_type_build')) { field_info_cache_clear(); } } /** - * Implements hook_entity_info_alter(). + * Implements hook_entity_type_alter(). */ -function field_test_entity_info_alter(&$entity_info) { - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ +function field_test_entity_type_alter(array &$entity_types) { + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ foreach (field_test_entity_info_translatable() as $entity_type => $translatable) { - $entity_info[$entity_type]->set('translatable', $translatable); + $entity_types[$entity_type]->set('translatable', $translatable); } } diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index a524bb9..fb9d263 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -72,14 +72,14 @@ function field_test_menu() { * field_test_memorize(); * * // call some Field API functions that invoke field_test hooks - * entity_create('field_entity', $field_definition)->save(); + * entity_create('field_config', $field_definition)->save(); * * // retrieve and reset the memorized hook call data * $mem = field_test_memorize(); * - * // make sure hook_field_create_field() is invoked correctly - * assertEqual(count($mem['field_test_field_entity_create']), 1); - * assertEqual($mem['field_test_field_entity_create'][0], array($field)); + * // make sure hook_field_config_create() is invoked correctly + * assertEqual(count($mem['field_test_field_config_create']), 1); + * assertEqual($mem['field_test_field_config_create'][0], array($field)); * @endcode * * @param $key @@ -104,9 +104,9 @@ function field_test_memorize($key = NULL, $value = NULL) { } /** - * Memorize calls to field_test_field_entity_create() for field creation. + * Memorize calls to field_test_field_config_create() for field creation. */ -function field_test_field_entity_create(FieldInterface $field) { +function field_test_field_config_create(FieldInterface $field) { $args = func_get_args(); field_test_memorize(__FUNCTION__, $args); } diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 87b3906..08c1cf6 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -130,16 +130,16 @@ function field_ui_element_info() { } /** - * Implements hook_entity_info(). + * Implements hook_entity_type_build(). */ -function field_ui_entity_info(&$entity_info) { - /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ - $entity_info['field_instance']->setFormClass('delete', 'Drupal\field_ui\Form\FieldDeleteForm'); - $entity_info['field_entity']->setListClass('Drupal\field_ui\FieldListController'); - - foreach ($entity_info as $info) { - if ($bundle = $info->getBundleOf()) { - $info +function field_ui_entity_type_build(array &$entity_types) { + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ + $entity_types['field_instance_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldInstanceConfigDeleteForm'); + $entity_types['field_config']->setListClass('Drupal\field_ui\FieldConfigListController'); + + foreach ($entity_types as $entity_type) { + if ($bundle = $entity_type->getBundleOf()) { + $entity_type ->setLinkTemplate('field_ui-fields', "field_ui.overview_$bundle") ->setLinkTemplate('field_ui-form-display', "field_ui.form_display_overview_$bundle") ->setLinkTemplate('field_ui-display', "field_ui.display_overview_$bundle"); diff --git a/core/modules/field_ui/field_ui.routing.yml b/core/modules/field_ui/field_ui.routing.yml index b840770..826150b 100644 --- a/core/modules/field_ui/field_ui.routing.yml +++ b/core/modules/field_ui/field_ui.routing.yml @@ -1,7 +1,7 @@ field_ui.list: path: '/admin/reports/fields' defaults: - _entity_list: 'field_entity' + _entity_list: 'field_config' _title: 'Field list' requirements: _permission: 'administer content types' diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Access/FieldDeleteAccessCheck.php b/core/modules/field_ui/lib/Drupal/field_ui/Access/FieldDeleteAccessCheck.php index c8f931b..c6eadc4 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Access/FieldDeleteAccessCheck.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Access/FieldDeleteAccessCheck.php @@ -21,7 +21,7 @@ class FieldDeleteAccessCheck implements AccessInterface { * {@inheritdoc} */ public function access(Route $route, Request $request, AccountInterface $account) { - $field_instance = $request->attributes->get('field_instance'); + $field_instance = $request->attributes->get('field_instance_config'); if (!$field_instance->getField()->isLocked()) { $permission = $route->getRequirement('_field_ui_field_delete_access'); return $account->hasPermission($permission) ? static::ALLOW : static::DENY; diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldConfigListController.php similarity index 94% rename from core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php rename to core/modules/field_ui/lib/Drupal/field_ui/FieldConfigListController.php index 9ccfe22..2b473ae 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldConfigListController.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\field_ui\FieldListController. + * Contains \Drupal\field_ui\FieldConfigListController. */ namespace Drupal\field_ui; @@ -17,7 +17,7 @@ /** * Provides a listing of fields. */ -class FieldListController extends ConfigEntityListController { +class FieldConfigListController extends ConfigEntityListController { /** * An array of information about field types. @@ -48,7 +48,7 @@ class FieldListController extends ConfigEntityListController { protected $fieldTypeManager; /** - * Constructs a new EntityListController object. + * Constructs a new FieldConfigListController object. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index e281f0e..2b03c6f 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -12,7 +12,7 @@ use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\field_ui\OverviewBase; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\field\Entity\Field; +use Drupal\field\Entity\FieldConfig; /** * Field UI field overview form. @@ -124,7 +124,7 @@ public function buildForm(array $form, array &$form_state, $entity_type_id = NUL $field = $instance->getField(); $route_parameters = array( $this->bundleEntityType => $this->bundle, - 'field_instance' => $instance->id(), + 'field_instance_config' => $instance->id(), ); $table[$name] = array( '#attributes' => array( @@ -212,7 +212,7 @@ public function buildForm(array $form, array &$form_state, $entity_type_id = NUL '#description' => $this->t('A unique machine-readable name containing letters, numbers, and underscores.'), // Calculate characters depending on the length of the field prefix // setting. Maximum length is 32. - '#maxlength' => Field::NAME_MAX_LENGTH - strlen($field_prefix), + '#maxlength' => FieldConfig::NAME_MAX_LENGTH - strlen($field_prefix), '#prefix' => '
 
', '#machine_name' => array( 'source' => array('fields', $name, 'label'), @@ -406,8 +406,8 @@ public function submitForm(array &$form, array &$form_state) { // Create the field and instance. try { - $this->entityManager->getStorageController('field_entity')->create($field)->save(); - $new_instance = $this->entityManager->getStorageController('field_instance')->create($instance); + $this->entityManager->getStorageController('field_config')->create($field)->save(); + $new_instance = $this->entityManager->getStorageController('field_instance_config')->create($instance); $new_instance->save(); // Make sure the field is displayed in the 'default' form mode (using @@ -428,7 +428,7 @@ public function submitForm(array &$form, array &$form_state) { // configured for new fields. $route_parameters = array( $this->bundleEntityType => $this->bundle, - 'field_instance' => $new_instance->id(), + 'field_instance_config' => $new_instance->id(), ); $destinations[] = array('route_name' => 'field_ui.field_edit_' . $this->entity_type, 'route_parameters' => $route_parameters); $destinations[] = array('route_name' => 'field_ui.instance_edit_' . $this->entity_type, 'route_parameters' => $route_parameters); @@ -458,7 +458,7 @@ public function submitForm(array &$form, array &$form_state) { ); try { - $new_instance = $this->entityManager->getStorageController('field_instance')->create($instance); + $new_instance = $this->entityManager->getStorageController('field_instance_config')->create($instance); $new_instance->save(); // Make sure the field is displayed in the 'default' form mode (using @@ -479,7 +479,7 @@ public function submitForm(array &$form, array &$form_state) { 'route_name' => 'field_ui.instance_edit_' . $this->entity_type, 'route_parameters' => array( $this->bundleEntityType => $this->bundle, - 'field_instance' => $new_instance->id(), + 'field_instance_config' => $new_instance->id(), ), ); // Store new field information for any additional submit handlers. @@ -526,7 +526,7 @@ protected function getExistingFieldOptions() { // Load the instances and build the list of options. if ($instance_ids) { $field_types = $this->fieldTypeManager->getDefinitions(); - $instances = $this->entityManager->getStorageController('field_instance')->loadMultiple($instance_ids); + $instances = $this->entityManager->getStorageController('field_instance_config')->loadMultiple($instance_ids); foreach ($instances as $instance) { // Do not show: // - locked fields, diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php index 8536d2a..5d40f60 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php @@ -85,8 +85,8 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance = NULL) { - $this->instance = $form_state['instance'] = $field_instance; + public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance_config = NULL) { + $this->instance = $form_state['instance'] = $field_instance_config; $form['#title'] = $this->instance->label(); $field = $this->instance->getField(); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceConfigDeleteForm.php similarity index 93% rename from core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php rename to core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceConfigDeleteForm.php index f7ac702..87dfafc 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceConfigDeleteForm.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\field_ui\Form\FieldDeleteForm. + * Contains \Drupal\field_ui\Form\FieldInstanceConfigDeleteForm. */ namespace Drupal\field_ui\Form; @@ -15,7 +15,7 @@ /** * Provides a form for removing a field instance from a bundle. */ -class FieldDeleteForm extends EntityConfirmFormBase { +class FieldInstanceConfigDeleteForm extends EntityConfirmFormBase { /** * The entity manager. @@ -25,7 +25,7 @@ class FieldDeleteForm extends EntityConfirmFormBase { protected $entityManager; /** - * Constructs a new FieldDeleteForm object. + * Constructs a new FieldInstanceConfigDeleteForm object. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php index 870436f..79aabe0 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php @@ -62,8 +62,8 @@ public function getFormId() { /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance = NULL) { - $this->instance = $form_state['instance'] = $field_instance; + public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance_config = NULL) { + $this->instance = $form_state['instance'] = $field_instance_config; $bundle = $this->instance->bundle; $entity_type = $this->instance->entity_type; @@ -220,7 +220,7 @@ public function delete(array &$form, array &$form_state) { 'route_name' => 'field_ui.delete_' . $this->instance->entity_type, 'route_parameters' => array( $entity_type->getBundleEntityType() => $this->instance->bundle, - 'field_instance' => $this->instance->id(), + 'field_instance_config' => $this->instance->id(), ), 'options' => array( 'query' => $destination, @@ -231,14 +231,14 @@ public function delete(array &$form, array &$form_state) { /** * The _title_callback for the field instance settings form. * - * @param \Drupal\field\FieldInstanceInterface $field_instance + * @param \Drupal\field\FieldInstanceInterface $field_instance_config * The field instance. * * @return string * The label of the field instance. */ - public function getTitle(FieldInstanceInterface $field_instance) { - return String::checkPlain($field_instance->label()); + public function getTitle(FieldInstanceInterface $field_instance_config) { + return String::checkPlain($field_instance_config->label()); } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php index fbee6aa..dacd9b9 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php @@ -49,7 +49,7 @@ protected function alterRoutes(RouteCollection $collection, $provider) { $path = $entity_route->getPath(); $route = new Route( - "$path/fields/{field_instance}", + "$path/fields/{field_instance_config}", array( '_form' => '\Drupal\field_ui\Form\FieldInstanceEditForm', '_title_callback' => '\Drupal\field_ui\Form\FieldInstanceEditForm::getTitle', @@ -59,15 +59,15 @@ protected function alterRoutes(RouteCollection $collection, $provider) { $collection->add("field_ui.instance_edit_$entity_type_id", $route); $route = new Route( - "$path/fields/{field_instance}/field", + "$path/fields/{field_instance_config}/field", array('_form' => '\Drupal\field_ui\Form\FieldEditForm'), array('_permission' => 'administer ' . $entity_type_id . ' fields') ); $collection->add("field_ui.field_edit_$entity_type_id", $route); $route = new Route( - "$path/fields/{field_instance}/delete", - array('_entity_form' => 'field_instance.delete'), + "$path/fields/{field_instance_config}/delete", + array('_entity_form' => 'field_instance_config.delete'), array('_field_ui_field_delete_access' => 'administer ' . $entity_type_id . ' fields') ); $collection->add("field_ui.delete_$entity_type_id", $route); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index f86f50a..70017fd 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -48,7 +48,7 @@ function setUp() { 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', ); - entity_create('field_entity', $field)->save(); + entity_create('field_config', $field)->save(); $instance = array( 'field_name' => 'field_' . $vocabulary->id(), @@ -56,7 +56,7 @@ function setUp() { 'label' => 'Tags', 'bundle' => 'article', ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display('node', 'article', 'default') ->setComponent('field_' . $vocabulary->id()) @@ -282,12 +282,12 @@ function testFieldPrefix() { function testDefaultValue() { // Create a test field and instance. $field_name = 'test'; - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => $field_name, 'entity_type' => 'node', 'type' => 'test_field' ))->save(); - $instance = entity_create('field_instance', array( + $instance = entity_create('field_instance_config', array( 'field_name' => $field_name, 'entity_type' => 'node', 'bundle' => $this->type, @@ -388,7 +388,7 @@ function testDeleteField() { function testLockedField() { // Create a locked field and attach it to a bundle. We need to do this // programatically as there's no way to create a locked field through UI. - $field = entity_create('field_entity', array( + $field = entity_create('field_config', array( 'name' => strtolower($this->randomName(8)), 'entity_type' => 'node', 'type' => 'test_field', @@ -396,7 +396,7 @@ function testLockedField() { 'locked' => TRUE )); $field->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => $field->name, 'entity_type' => 'node', 'bundle' => $this->type, @@ -431,7 +431,7 @@ function testHiddenFields() { // Create a field and an instance programmatically. $field_name = 'hidden_test_field'; - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => $field_name, 'entity_type' => 'node', 'type' => $field_name, @@ -442,11 +442,11 @@ function testHiddenFields() { 'entity_type' => 'node', 'label' => t('Hidden field'), ); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display('node', $this->type, 'default') ->setComponent($field_name) ->save(); - $this->assertTrue(entity_load('field_instance', 'node.' . $this->type . '.' . $field_name), format_string('An instance of the field %field was created programmatically.', array('%field' => $field_name))); + $this->assertTrue(entity_load('field_instance_config', 'node.' . $this->type . '.' . $field_name), format_string('An instance of the field %field was created programmatically.', array('%field' => $field_name))); // Check that the newly added instance appears on the 'Manage Fields' // screen. @@ -530,13 +530,13 @@ function testDeleteTaxonomyField() { */ function testHelpDescriptions() { // Create an image field - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => 'field_image', 'entity_type' => 'node', 'type' => 'image', ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'field_name' => 'field_image', 'entity_type' => 'node', 'label' => 'Image', diff --git a/core/modules/file/config/views.view.files.yml b/core/modules/file/config/views.view.files.yml index e192361..cf35275 100644 --- a/core/modules/file/config/views.view.files.yml +++ b/core/modules/file/config/views.view.files.yml @@ -1039,5 +1039,4 @@ label: Files module: file id: files tag: default -uuid: 4b47e09e-16e0-494b-b447-7166191dbb6e langcode: en diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 3252cec..8a64332 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -5,6 +5,7 @@ * Field module functionality for the File module. */ +use Drupal\Component\Utility\Html; use Drupal\field\FieldInterface; /** @@ -181,8 +182,8 @@ function theme_file_upload_help($variables) { $descriptions = array(); - if (strlen($description)) { - $descriptions[] = _filter_htmlcorrector($description); + if (!empty($description)) { + $descriptions[] = Html::normalize($description); } if (isset($cardinality)) { if ($cardinality == -1) { diff --git a/core/modules/file/file.install b/core/modules/file/file.install index 5d5f6c5..fb5a4eb 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -5,9 +5,6 @@ * Install, update and uninstall functions for File module. */ -use Drupal\Core\Entity\FieldableDatabaseStorageController; -use Drupal\field\Entity\Field; - /** * Implements hook_schema(). */ diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 5546caa..4d350e7 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -110,8 +110,8 @@ function file_load($fid, $reset = FALSE) { /** * Returns the file usage service. * - * @deprecated as of Drupal 8.0. Use \Drupal::service('file.usage') instead, or - * even better have the file usage service injected into your object. + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::service('file.usage'). * * @return \Drupal\file\FileUsage\FileUsageInterface. */ @@ -652,7 +652,7 @@ function file_file_download($uri, $field_type = 'file') { // Default to FALSE and let entities overrule this ruling. $grants = array('system' => FALSE); foreach (\Drupal::moduleHandler()->getImplementations('file_download_access') as $module) { - $grants = array_merge($grants, array($module => module_invoke($module, 'file_download_access', $field, $entity, $file))); + $grants = array_merge($grants, array($module => \Drupal::moduleHandler()->invoke($module, 'file_download_access', array($field, $entity, $file)))); } // Allow other modules to alter the returned grants/denies. $context = array( diff --git a/core/modules/file/lib/Drupal/file/Entity/File.php b/core/modules/file/lib/Drupal/file/Entity/File.php index 62a754b..d74dee8 100644 --- a/core/modules/file/lib/Drupal/file/Entity/File.php +++ b/core/modules/file/lib/Drupal/file/Entity/File.php @@ -17,7 +17,7 @@ /** * Defines the file entity class. * - * @EntityType( + * @ContentEntityType( * id = "file", * label = @Translation("File"), * controllers = { diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php b/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php index 00fb296..94529a0 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php @@ -44,6 +44,7 @@ protected function defaultDisplayOptions() { // Add permission-based access control. $display_options['access']['type'] = 'perm'; + $display_options['access']['provider'] = 'user'; // Remove the default fields, since we are customizing them here. unset($display_options['fields']); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index 75339a3..82d043a 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -76,7 +76,7 @@ function createFileField($name, $entity_type, $bundle, $field_settings = array() 'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1, ); $field_definition['settings'] = array_merge($field_definition['settings'], $field_settings); - $field = entity_create('field_entity', $field_definition); + $field = entity_create('field_config', $field_definition); $field->save(); $this->attachFileField($name, $entity_type, $bundle, $instance_settings, $widget_settings); @@ -109,7 +109,7 @@ function attachFileField($name, $entity_type, $bundle, $instance_settings = arra 'settings' => array(), ); $instance['settings'] = array_merge($instance['settings'], $instance_settings); - entity_create('field_instance', $instance)->save(); + entity_create('field_instance_config', $instance)->save(); entity_get_form_display($entity_type, $bundle, 'default') ->setComponent($name, array( diff --git a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php index 468a83a..0f40a14 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php @@ -45,13 +45,13 @@ public function setUp() { $this->installSchema('file', 'file_managed'); $this->installSchema('file', 'file_usage'); - entity_create('field_entity', array( + entity_create('field_config', array( 'name' => 'file_test', 'entity_type' => 'entity_test', 'type' => 'file', 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, ))->save(); - entity_create('field_instance', array( + entity_create('field_instance_config', array( 'entity_type' => 'entity_test', 'field_name' => 'file_test', 'bundle' => 'entity_test', diff --git a/core/modules/filter/config/filter.format.plain_text.yml b/core/modules/filter/config/filter.format.plain_text.yml index 37650f9..70abb88 100644 --- a/core/modules/filter/config/filter.format.plain_text.yml +++ b/core/modules/filter/config/filter.format.plain_text.yml @@ -4,7 +4,6 @@ # - may be modified by installation profiles to have other properties. format: plain_text name: 'Plain text' -uuid: 7dd77dca-6a80-4538-b10d-133fa66d42f0 status: true weight: 10 roles: diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 63414ed..ca50030 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -5,6 +5,7 @@ * Framework for handling the filtering of content. */ +use Drupal\Component\Utility\Html; use Drupal\Component\Utility\String; use Drupal\Core\Cache\Cache; use Drupal\Core\Language\Language; @@ -420,7 +421,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE, $cache_id = ''; if ($cache) { $cache_id = $format->format . ':' . $langcode . ':' . hash('sha256', $text); - if ($cached = cache('filter')->get($cache_id)) { + if ($cached = \Drupal::cache('filter')->get($cache_id)) { return $cached->data; } } @@ -459,7 +460,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE, // automatically flushed when the text format is updated. // @see \Drupal\filter\Entity\FilterFormat::save() if ($cache) { - cache('filter')->set($cache_id, $text, Cache::PERMANENT, array('filter_format' => $format->id())); + \Drupal::cache('filter')->set($cache_id, $text, Cache::PERMANENT, array('filter_format' => $format->id())); } return $text; @@ -694,103 +695,6 @@ function _filter_tips($format_id, $long = FALSE) { } /** - * Parses an HTML snippet and returns it as a DOM object. - * - * This function loads the body part of a partial (X)HTML document and returns - * a full DOMDocument object that represents this document. You can use - * filter_dom_serialize() to serialize this DOMDocument back to a XHTML - * snippet. - * - * @param $text - * The partial (X)HTML snippet to load. Invalid markup will be corrected on - * import. - * - * @return - * A DOMDocument that represents the loaded (X)HTML snippet. - */ -function filter_dom_load($text) { - $dom_document = new DOMDocument(); - // Ignore warnings during HTML soup loading. - @$dom_document->loadHTML('' . $text . ''); - - return $dom_document; -} - -/** - * Converts a DOM object back to an HTML snippet. - * - * The function serializes the body part of a DOMDocument back to an XHTML - * snippet. The resulting XHTML snippet will be properly formatted to be - * compatible with HTML user agents. - * - * @param $dom_document - * A DOMDocument object to serialize, only the tags below - * the first node will be converted. - * - * @return - * A valid (X)HTML snippet, as a string. - */ -function filter_dom_serialize($dom_document) { - $body_node = $dom_document->getElementsByTagName('body')->item(0); - $body_content = ''; - - foreach ($body_node->getElementsByTagName('script') as $node) { - filter_dom_serialize_escape_cdata_element($dom_document, $node); - } - - foreach ($body_node->getElementsByTagName('style') as $node) { - filter_dom_serialize_escape_cdata_element($dom_document, $node, '/*', '*/'); - } - - foreach ($body_node->childNodes as $child_node) { - $body_content .= $dom_document->saveXML($child_node); - } - return $body_content; -} - -/** - * Adds comments around the childNodes as $node) { - if (get_class($node) == 'DOMCdataSection') { - // See drupal_get_js(). This code is more or less duplicated there. - $embed_prefix = "\n{$comment_end}\n"; - - // Prevent invalid cdata escaping as this would throw a DOM error. - // This is the same behavior as found in libxml2. - // Related W3C standard: http://www.w3.org/TR/REC-xml/#dt-cdsection - // Fix explanation: http://en.wikipedia.org/wiki/CDATA#Nesting - $data = str_replace(']]>', ']]]]>', $node->data); - - $fragment = $dom_document->createDocumentFragment(); - $fragment->appendXML($embed_prefix . $data . $embed_suffix); - $dom_element->appendChild($fragment); - $dom_element->removeChild($node); - } - } -} - -/** * Prepares variables for text format guideline templates. * * Default template: filter-guidelines.html.twig. @@ -878,12 +782,12 @@ function _filter_html($text, $filter) { $text = filter_xss($text, $allowed_tags); if ($filter->settings['filter_html_nofollow']) { - $html_dom = filter_dom_load($text); + $html_dom = Html::load($text); $links = $html_dom->getElementsByTagName('a'); foreach ($links as $link) { $link->setAttribute('rel', 'nofollow'); } - $text = filter_dom_serialize($html_dom); + $text = Html::serialize($html_dom); } return trim($text); @@ -1128,13 +1032,6 @@ function _filter_url_trim($text, $length = NULL) { } /** - * Scans the input and makes sure that HTML tags are properly closed. - */ -function _filter_htmlcorrector($text) { - return filter_dom_serialize(filter_dom_load($text)); -} - -/** * Converts line breaks into

and
in an intelligent fashion. * * Based on: http://photomatt.net/scripts/autop @@ -1219,7 +1116,7 @@ function _filter_html_image_secure_process($text) { // Find the directory on the server where index.php resides. $local_dir = DRUPAL_ROOT . '/'; - $html_dom = filter_dom_load($text); + $html_dom = Html::load($text); $images = $html_dom->getElementsByTagName('img'); foreach ($images as $image) { $src = $image->getAttribute('src'); @@ -1245,7 +1142,7 @@ function _filter_html_image_secure_process($text) { // indicator. See filter_filter_secure_image_alter(). \Drupal::moduleHandler()->alter('filter_secure_image', $image); } - $text = filter_dom_serialize($html_dom); + $text = Html::serialize($html_dom); return $text; } diff --git a/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php index 15537ac..6666c86 100644 --- a/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php +++ b/core/modules/filter/lib/Drupal/filter/Entity/FilterFormat.php @@ -17,7 +17,7 @@ /** * Represents a text format. * - * @EntityType( + * @ConfigEntityType( * id = "filter_format", * label = @Translation("Text format"), * controllers = { @@ -28,7 +28,6 @@ * }, * "list" = "Drupal\filter\FilterFormatListController", * "access" = "Drupal\filter\FilterFormatAccessController", - * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController" * }, * config_prefix = "filter.format", * admin_permission = "administer filters", @@ -183,7 +182,7 @@ public function disable() { parent::disable(); // Allow modules to react on text format deletion. - module_invoke_all('filter_format_disable', $this); + \Drupal::moduleHandler()->invokeAll('filter_format_disable', array($this)); // Clear the filter cache whenever a text format is disabled. filter_formats_reset(); diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterCaption.php b/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterCaption.php index 5b5ce63..51cb70a 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterCaption.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterCaption.php @@ -7,6 +7,7 @@ namespace Drupal\filter\Plugin\Filter; +use Drupal\Component\Utility\Html; use Drupal\Component\Utility\String; use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Xss; @@ -30,7 +31,7 @@ class FilterCaption extends FilterBase { public function process($text, $langcode, $cache, $cache_id) { if (stristr($text, 'data-caption') !== FALSE || stristr($text, 'data-align') !== FALSE) { - $dom = filter_dom_load($text); + $dom = Html::load($text); $xpath = new \DOMXPath($dom); foreach ($xpath->query('//*[@data-caption or @data-align]') as $node) { $caption = NULL; @@ -82,7 +83,7 @@ public function process($text, $langcode, $cache, $cache_id) { $altered_html = drupal_render($filter_caption); // Load the altered HTML into a new DOMDocument and retrieve the element. - $updated_node = filter_dom_load($altered_html)->getElementsByTagName('body') + $updated_node = Html::load($altered_html)->getElementsByTagName('body') ->item(0) ->childNodes ->item(0); @@ -94,7 +95,7 @@ public function process($text, $langcode, $cache, $cache_id) { $node->parentNode->replaceChild($updated_node, $node); } - return filter_dom_serialize($dom); + return Html::serialize($dom); } return $text; diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterHtmlCorrector.php b/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterHtmlCorrector.php index 8d9b8e0..bc0a036 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterHtmlCorrector.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterHtmlCorrector.php @@ -7,6 +7,7 @@ namespace Drupal\filter\Plugin\Filter; +use Drupal\Component\Utility\Html; use Drupal\filter\Plugin\FilterBase; /** @@ -25,7 +26,7 @@ class FilterHtmlCorrector extends FilterBase { * {@inheritdoc} */ public function process($text, $langcode, $cache, $cache_id) { - return _filter_htmlcorrector($text); + return Html::normalize($text); } } diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php index e10c5ca..248a9dd 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php @@ -154,7 +154,7 @@ function testFilterAdmin() { $this->drupalGet('admin/config/content/formats/manage/' . $restricted); $this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], 'Allowed HTML tag added.'); - $this->assertTrue(cache('filter')->isEmpty(), 'Cache cleared.'); + $this->assertTrue(\Drupal::cache('filter')->isEmpty(), 'Cache cleared.'); $elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', array( ':first' => 'filters[' . $first_filter . '][weight]', diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php index ae74dc1..b9b6b71 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php @@ -13,6 +13,14 @@ * Tests the default filter functionality in the Filter module. */ class FilterDefaultFormatTest extends WebTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('filter'); + public static function getInfo() { return array( 'name' => 'Default text format functionality', diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterNoFormatTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterNoFormatTest.php index 59629ba..9f2090c 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterNoFormatTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterNoFormatTest.php @@ -13,6 +13,14 @@ * Tests the behavior of check_markup() when it is called without text format. */ class FilterNoFormatTest extends WebTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('filter'); + public static function getInfo() { return array( 'name' => 'Unassigned text format functionality', diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterUnitTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterUnitTest.php index f686cee..a51d6b9 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterUnitTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterUnitTest.php @@ -7,6 +7,7 @@ namespace Drupal\filter\Tests; +use Drupal\Component\Utility\Html; use Drupal\simpletest\DrupalUnitTestBase; use Drupal\filter\FilterBag; @@ -741,117 +742,117 @@ function testUrlFilterContent() { */ function testHtmlCorrectorFilter() { // Tag closing. - $f = _filter_htmlcorrector('

text'); + $f = Html::normalize('

text'); $this->assertEqual($f, '

text

', 'HTML corrector -- tag closing at the end of input.'); - $f = _filter_htmlcorrector('

text

text'); + $f = Html::normalize('

text

text'); $this->assertEqual($f, '

text

text

', 'HTML corrector -- tag closing.'); - $f = _filter_htmlcorrector("
  • e1
  • e2"); + $f = Html::normalize("
    • e1
    • e2"); $this->assertEqual($f, "
      • e1
      • e2
      ", 'HTML corrector -- unclosed list tags.'); - $f = _filter_htmlcorrector('
      content'); + $f = Html::normalize('
      content'); $this->assertEqual($f, '
      content
      ', 'HTML corrector -- unclosed tag with attribute.'); // XHTML slash for empty elements. - $f = _filter_htmlcorrector('

      '); + $f = Html::normalize('

      '); $this->assertEqual($f, '

      ', 'HTML corrector -- XHTML closing slash.'); - $f = _filter_htmlcorrector('

      test

      '); + $f = Html::normalize('

      test

      '); $this->assertEqual($f, '

      test

      ', 'HTML corrector -- Convert uppercased tags to proper lowercased ones.'); - $f = _filter_htmlcorrector('

      test

      '); + $f = Html::normalize('

      test

      '); $this->assertEqual($f, '

      test

      ', 'HTML corrector -- Convert uppercased tags to proper lowercased ones.'); - $f = _filter_htmlcorrector('test
      '); + $f = Html::normalize('test
      '); $this->assertEqual($f, 'test
      ', 'HTML corrector -- Let proper XHTML pass through.'); - $f = _filter_htmlcorrector('test
      '); + $f = Html::normalize('test
      '); $this->assertEqual($f, 'test
      ', 'HTML corrector -- Let proper XHTML pass through, but ensure there is a single space before the closing slash.'); - $f = _filter_htmlcorrector('test
      '); + $f = Html::normalize('test
      '); $this->assertEqual($f, 'test
      ', 'HTML corrector -- Let proper XHTML pass through, but ensure there are not too many spaces before the closing slash.'); - $f = _filter_htmlcorrector(''); + $f = Html::normalize(''); $this->assertEqual($f, '', 'HTML corrector -- Convert XHTML that is properly formed but that would not be compatible with typical HTML user agents.'); - $f = _filter_htmlcorrector('test1
      test2'); + $f = Html::normalize('test1
      test2'); $this->assertEqual($f, 'test1
      test2', 'HTML corrector -- Automatically close single tags.'); - $f = _filter_htmlcorrector('line1
      line2'); + $f = Html::normalize('line1
      line2'); $this->assertEqual($f, 'line1
      line2', 'HTML corrector -- Automatically close single tags.'); - $f = _filter_htmlcorrector('line1
      line2'); + $f = Html::normalize('line1
      line2'); $this->assertEqual($f, 'line1
      line2', 'HTML corrector -- Automatically close single tags.'); - $f = _filter_htmlcorrector('test'); + $f = Html::normalize('test'); $this->assertEqual($f, 'test', 'HTML corrector -- Automatically close single tags.'); - $f = _filter_htmlcorrector('

      '); + $f = Html::normalize('

      '); $this->assertEqual($f, '
      ', "HTML corrector -- Transform empty tags to a single closed tag if the tag's content model is EMPTY."); - $f = _filter_htmlcorrector('
      '); + $f = Html::normalize('
      '); $this->assertEqual($f, '
      ', "HTML corrector -- Do not transform empty tags to a single closed tag if the tag's content model is not EMPTY."); - $f = _filter_htmlcorrector('

      line1


      line2

      '); + $f = Html::normalize('

      line1


      line2

      '); $this->assertEqual($f, '

      line1


      line2', 'HTML corrector -- Move non-inline elements outside of inline containers.'); - $f = _filter_htmlcorrector('

      line1

      line2

      '); + $f = Html::normalize('

      line1

      line2

      '); $this->assertEqual($f, '

      line1

      line2
      ', 'HTML corrector -- Move non-inline elements outside of inline containers.'); - $f = _filter_htmlcorrector('

      test

      test

      \n'); + $f = Html::normalize('

      test

      test

      \n'); $this->assertEqual($f, '

      test

      test

      \n', 'HTML corrector -- Auto-close improperly nested tags.'); - $f = _filter_htmlcorrector('

      Line1
      bold stuff'); + $f = Html::normalize('

      Line1
      bold stuff'); $this->assertEqual($f, '

      Line1
      bold stuff

      ', 'HTML corrector -- Properly close unclosed tags, and remove useless closing tags.'); - $f = _filter_htmlcorrector('test '); + $f = Html::normalize('test '); $this->assertEqual($f, 'test ', 'HTML corrector -- Do not touch HTML comments.'); - $f = _filter_htmlcorrector('test '); + $f = Html::normalize('test '); $this->assertEqual($f, 'test ', 'HTML corrector -- Do not touch HTML comments.'); - $f = _filter_htmlcorrector('test '); $this->assertEqual($f, 'test ', 'HTML corrector -- Do not touch HTML comments.'); - $f = _filter_htmlcorrector('test '); + $f = Html::normalize('test '); $this->assertEqual($f, 'test ', 'HTML corrector -- Do not touch HTML comments.'); - $f = _filter_htmlcorrector('test '); + $f = Html::normalize('test '); $this->assertEqual($f, 'test ', 'HTML corrector -- Do not touch HTML comments.'); - $f = _filter_htmlcorrector('

      test\n

      \n'); + $f = Html::normalize('

      test\n

      \n'); $this->assertEqual($f, '

      test\n

      \n', 'HTML corrector -- New-lines are accepted and kept as-is.'); - $f = _filter_htmlcorrector('

      دروبال'); + $f = Html::normalize('

      دروبال'); $this->assertEqual($f, '

      دروبال

      ', 'HTML corrector -- Encoding is correctly kept.'); - $f = _filter_htmlcorrector(''); + $f = Html::normalize(''); $this->assertEqual($f, '', 'HTML corrector -- CDATA added to script element'); - $f = _filter_htmlcorrector('

      '); + $f = Html::normalize('

      '); $this->assertEqual($f, '

      ', 'HTML corrector -- CDATA added to a nested script element'); - $f = _filter_htmlcorrector('

      '); + $f = Html::normalize('

      '); $this->assertEqual($f, '

      ', 'HTML corrector -- CDATA added to a style element.'); - $filtered_data = _filter_htmlcorrector('