diff --git a/core/lib/Drupal/Core/Render/Element/StatusMessages.php b/core/lib/Drupal/Core/Render/Element/StatusMessages.php index c3dcd189e4..530457fd90 100644 --- a/core/lib/Drupal/Core/Render/Element/StatusMessages.php +++ b/core/lib/Drupal/Core/Render/Element/StatusMessages.php @@ -30,7 +30,7 @@ public function getInfo() { // of that specific type. '#display' => NULL, '#pre_render' => [ - get_class() . '::preRenderGeneratePlaceholder', + get_class() . '::generatePlaceholder', ], ]; } @@ -43,25 +43,8 @@ public function getInfo() { * * @return array * The updated renderable array containing the placeholder. - * - * @deprecated Use - * \Drupal\Core\Render\Element\StatusMessages::preRenderGeneratePlaceholder - * instead. */ public static function generatePlaceholder(array $element) { - return static::preRenderGeneratePlaceholder($element); - } - - /** - * #pre_render callback to generate a placeholder. - * - * @param array $element - * A renderable array. - * - * @return array - * The updated renderable array containing the placeholder. - */ - public static function preRenderGeneratePlaceholder(array $element) { $element = [ '#lazy_builder' => [get_class() . '::renderMessages', [$element['#display']]], '#create_placeholder' => TRUE, diff --git a/core/lib/Drupal/Core/Render/Element/Table.php b/core/lib/Drupal/Core/Render/Element/Table.php index 0f54584032..2a5082b18d 100644 --- a/core/lib/Drupal/Core/Render/Element/Table.php +++ b/core/lib/Drupal/Core/Render/Element/Table.php @@ -64,7 +64,7 @@ class Table extends FormElement { * {@inheritdoc} */ public function getInfo() { - $class = get_called_class(); + $class = get_class(); return [ '#header' => [], '#rows' => [], diff --git a/core/modules/filter/src/Element/TextFormat.php b/core/modules/filter/src/Element/TextFormat.php index 350390a0d8..ff36c5d711 100644 --- a/core/modules/filter/src/Element/TextFormat.php +++ b/core/modules/filter/src/Element/TextFormat.php @@ -226,7 +226,7 @@ public static function processFormat(&$element, FormStateInterface $form_state, // Prepend #pre_render callback to replace field value with user notice // prior to rendering. $element['value'] += ['#pre_render' => []]; - array_unshift($element['value']['#pre_render'], [__CLASS__, 'preRenderCallback']); + array_unshift($element['value']['#pre_render'], [get_called_class(), 'accessDeniedCallback']); // Cosmetic adjustments. if (isset($element['value']['#rows'])) { @@ -260,7 +260,7 @@ public static function processFormat(&$element, FormStateInterface $form_state, * * @return array */ - public static function preRenderCallback(array $element) { + public static function accessDeniedCallback(array $element) { $element['#value'] = t('This field has been disabled because you do not have sufficient permissions to edit it.'); return $element; } diff --git a/core/modules/system/src/Tests/Theme/FunctionsTest.php b/core/modules/system/src/Tests/Theme/FunctionsTest.php index c22e9394f3..c9f2873fb3 100644 --- a/core/modules/system/src/Tests/Theme/FunctionsTest.php +++ b/core/modules/system/src/Tests/Theme/FunctionsTest.php @@ -6,7 +6,6 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Render\Element\Link; -use Drupal\Core\Render\RenderCallbackInterface; use Drupal\Core\Session\UserSession; use Drupal\Core\Url; use Drupal\simpletest\WebTestBase; @@ -16,7 +15,7 @@ * * @group Theme */ -class FunctionsTest extends WebTestBase implements RenderCallbackInterface { +class FunctionsTest extends WebTestBase { /** * Modules to enable. diff --git a/core/modules/views/src/Form/ViewsFormMainForm.php b/core/modules/views/src/Form/ViewsFormMainForm.php index 902a129ae2..b2d8ad894b 100644 --- a/core/modules/views/src/Form/ViewsFormMainForm.php +++ b/core/modules/views/src/Form/ViewsFormMainForm.php @@ -2,9 +2,12 @@ namespace Drupal\views\Form; +use Drupal\Component\Render\MarkupInterface; +use Drupal\Component\Utility\Html; use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\RenderCallbackInterface; +use Drupal\views\Render\ViewsRenderPipelineMarkup; use Drupal\views\ViewExecutable; class ViewsFormMainForm implements FormInterface, RenderCallbackInterface { @@ -27,7 +30,34 @@ public function getFormId() { * in views_form_views_form. */ public static function preRenderViewsForm(array $element) { - return views_pre_render_views_form_views_form($element); + // Placeholders and their substitutions (usually rendered form elements). + $search = []; + $replace = []; + + // Add in substitutions provided by the form. + foreach ($element['#substitutions']['#value'] as $substitution) { + $field_name = $substitution['field_name']; + $row_id = $substitution['row_id']; + + $search[] = $substitution['placeholder']; + $replace[] = isset($element[$field_name][$row_id]) ? \Drupal::service('renderer')->render($element[$field_name][$row_id]) : ''; + } + // Add in substitutions from hook_views_form_substitutions(). + $substitutions = \Drupal::moduleHandler()->invokeAll('views_form_substitutions'); + foreach ($substitutions as $placeholder => $substitution) { + $search[] = Html::escape($placeholder); + // Ensure that any replacements made are safe to make. + if (!($substitution instanceof MarkupInterface)) { + $substitution = Html::escape($substitution); + } + $replace[] = $substitution; + } + + // Apply substitutions to the rendered output. + $output = str_replace($search, $replace, \Drupal::service('renderer')->render($element['output'])); + $element['output'] = ['#markup' => ViewsRenderPipelineMarkup::create($output)]; + + return $element; } /** @@ -44,7 +74,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ViewExecu $form['#prefix'] = '