diff --git a/core/includes/common.inc b/core/includes/common.inc index 633832a..4ced045 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3909,8 +3909,8 @@ function drupal_render_cache_generate_placeholder($callback, array $context, $to */ function drupal_pre_render_render_cache_placeholder($element) { $callback = $element['#callback']; - if (!is_callable($callback) && substr($callback, 0, 1) != '@') { - throw new Exception(t('#callback must be a callable function or of the form @service_id::method.')); + if (!is_callable($callback) && strpos($callback, ':') === FALSE) { + throw new Exception(t('#callback must be a callable function or of the form service_id:method.')); } $context = $element['#context']; if (!is_array($context)) { @@ -3949,25 +3949,14 @@ function _drupal_render_process_post_render_cache(array &$elements) { // is passed to the callback as well. This token is used to uniquely // identify the placeholder in the markup. $modified_elements = $elements; + /** @var \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver */ + $controller_resolver = \Drupal::service('controller_resolver'); foreach ($elements['#post_render_cache'] as $callback => $options) { - $callable = $callback; - // We support service callbacks in the form '@{service_id}::method' - // format. - if (substr($callback, 0, 1) == '@') { - // This is a service, split the method and service id from the callback. - list($service_id, $method) = explode('::', $callback); - // Remove the leading '@'. - $service_id = substr($service_id, 1); - if (($service = \Drupal::service($service_id)) && method_exists($service, $method)) { - // Refactor the callback into the a callable format. - $callable = array($service, $method); - } - else { - throw new Exception(t('Post render callback service %service either does not exist or has no %method method', array( - '%service' => $callback[0], - '%method' => $callback[1], - ))); - } + if (strpos($callback, '::') == FALSE) { + $callable = $controller_resolver->getControllerFromDefinition($callback); + } + else { + $callable = $callback; } foreach ($elements['#post_render_cache'][$callback] as $token => $context) { // The advanced option, when setting #post_render_cache directly. diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php index f2ebed5..895e5f3 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php @@ -164,7 +164,7 @@ public function viewElements(FieldItemListInterface $items) { else { $output['comment_form'] = array( '#type' => 'render_cache_placeholder', - '#callback' => '@comment.post_render_cache::renderForm', + '#callback' => 'comment.post_render_cache:renderForm', '#context' => array( 'entity_type' => $entity->getEntityTypeId(), 'entity_id' => $entity->id(),