Commit 886ca0b6 authored by catch's avatar catch
Browse files

Issue #3260780 by andypost: Remove deprecated code from common.inc

parent 57d1ee06
Loading
Loading
Loading
Loading
+0 −73
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@
 */

use Drupal\Component\Utility\Bytes;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\SortArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\DrupalKernel;
@@ -346,47 +345,6 @@ function drupal_attach_tabledrag(&$element, array $options) {
  $element['#attached']['library'][] = 'core/drupal.tabledrag';
}

/**
 * Renders an element.
 *
 * This function renders an element. The top level element is shown with show()
 * before rendering, so it will always be rendered even if hide() had been
 * previously used on it.
 *
 * @param $element
 *   The element to be rendered.
 *
 * @return
 *   The rendered element.
 *
 * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use
 *   \Drupal\Core\Render\RendererInterface::render() instead.
 *
 * @see https://www.drupal.org/node/2939099
 * @see \Drupal\Core\Render\RendererInterface
 * @see show()
 * @see hide()
 */
function render(&$element) {
  @trigger_error('The render() function is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Render\RendererInterface::render() instead. See https://www.drupal.org/node/2939099', E_USER_DEPRECATED);
  if (!$element && $element !== 0) {
    return NULL;
  }
  if (is_array($element)) {
    // Early return if this element was pre-rendered (no need to re-render).
    if (isset($element['#printed']) && $element['#printed'] == TRUE && isset($element['#markup']) && strlen($element['#markup']) > 0) {
      return $element['#markup'];
    }
    show($element);
    return \Drupal::service('renderer')->render($element);
  }
  else {
    // Safe-guard for inappropriate use of render() on flat variables: return
    // the variable as-is.
    return $element;
  }
}

/**
 * Hides an element from later rendering.
 *
@@ -577,37 +535,6 @@ function _drupal_flush_css_js() {
  Drupal::state()->set('system.css_js_query_string', base_convert(REQUEST_TIME, 10, 36));
}

/**
 * Outputs debug information.
 *
 * The debug information is passed on to trigger_error() after being converted
 * to a string using print_r() or var_export().
 *
 * @param $data
 *   Data to be output.
 * @param $label
 *   Label to prefix the data.
 * @param $print_r
 *   Flag to switch between print_r() and var_export() for data conversion to
 *   string. Set $print_r to FALSE to use var_export() instead of print_r().
 *   Passing recursive data structures to var_export() will generate an error.
 *
 * @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use dump()
 *   instead.
 *
 * @see https://www.drupal.org/node/3192283
 */
function debug($data, $label = NULL, $print_r = TRUE) {
  @trigger_error('debug() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use dump() instead. See https://www.drupal.org/node/3192283', E_USER_DEPRECATED);
  // Print $data contents to string.
  $string = Html::escape($print_r ? print_r($data, TRUE) : var_export($data, TRUE));

  // Display values with pre-formatting to increase readability.
  $string = '<pre>' . $string . '</pre>';

  trigger_error(trim($label ? "$label: $string" : $string));
}

/**
 * Assembles the Drupal Updater registry.
 *
+0 −5
Original line number Diff line number Diff line
name: 'Use render() and check its deprecation'
type: module
description: 'Use render() and check its deprecation.'
package: Testing
version: VERSION
+0 −12
Original line number Diff line number Diff line
render_deprecation.function:
  path: '/render_deprecation/function'
  defaults:
    _controller: 'Drupal\render_deprecation\RenderDeprecationController::buildRenderFunction'
  requirements:
    _access: 'TRUE'
render_deprecation.service:
  path: '/render_deprecation/service'
  defaults:
    _controller: 'Drupal\render_deprecation\RenderDeprecationController::buildRenderService'
  requirements:
    _access: 'TRUE'
+0 −39
Original line number Diff line number Diff line
<?php

namespace Drupal\render_deprecation;

use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Response;

class RenderDeprecationController implements ContainerAwareInterface {

  use ContainerAwareTrait;

  protected function renderArray() {
    return [
      'div' => [
        '#type' => 'container',
        '#attributes' => [
          'id' => 'render-deprecation-test-result',
        ],
        'info' => [
          '#markup' => 'Hello.',
        ],
      ],
    ];
  }

  public function buildRenderFunction() {
    $build = $this->renderArray();
    $render = render($build);
    return Response::create($render);
  }

  public function buildRenderService() {
    $build = $this->renderArray();
    $render = $this->container->get('renderer')->render($build);
    return Response::create($render);
  }

}
+0 −11
Original line number Diff line number Diff line
@@ -957,17 +957,6 @@ public function testDrupalGetHeader() {
    $this->drupalGetHeader('Content-Type');
  }

  /**
   * Tests legacy debug().
   *
   * @group legacy
   */
  public function testDebug() {
    $this->expectDeprecation('debug() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use dump() instead. See https://www.drupal.org/node/3192283');
    $this->expectError();
    debug("There's a star man waiting in the sky");
  }

  /**
   * Tests the dump() function provided by the var-dumper Symfony component.
   */
Loading