Commit 9bee4588 authored by catch's avatar catch

Issue #2311393 by tim.plunkett: Remove hook_element_info() and all references to it

parent d66acd16
......@@ -1200,7 +1200,7 @@ function show(&$element) {
* Retrieves the default properties for the defined element type.
*
* @param $type
* An element type as defined by hook_element_info().
* An element type as defined by an element plugin.
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* Use \Drupal::service('element_info')->getInfo() instead.
......@@ -1213,7 +1213,7 @@ function element_info($type) {
* Retrieves a single property for the defined element type.
*
* @param $type
* An element type as defined by hook_element_info().
* An element type as defined by an element plugin.
* @param $property_name
* The property within the element type that should be returned.
* @param $default
......
......@@ -135,7 +135,7 @@ public static function processMachineName(&$element, FormStateInterface $form_st
);
// A form element that only wants to set one #machine_name property (usually
// 'source' only) would leave all other properties undefined, if the defaults
// were defined in hook_element_info(). Therefore, we apply the defaults here.
// were defined by an element plugin. Therefore, we apply the defaults here.
$element['#machine_name'] += array(
'source' => array('label'),
'target' => '#' . $element['#id'],
......
......@@ -110,10 +110,7 @@ protected function buildInfo($theme_name) {
}
// Otherwise, rebuild and cache.
// @todo Remove this hook once all elements are converted to plugins in
// https://www.drupal.org/node/2311393.
$info = $this->moduleHandler->invokeAll('element_info');
$info = [];
foreach ($this->getDefinitions() as $element_type => $definition) {
$element = $this->createInstance($element_type);
$element_info = $element->getInfo();
......
......@@ -44,8 +44,6 @@ interface ElementInfoManagerInterface {
* - #title_display: optional string indicating if and how #title should be
* displayed (see form-element.html.twig).
*
* @see hook_element_info()
* @see hook_element_info_alter()
* @see \Drupal\Core\Render\Element\ElementInterface
* @see \Drupal\Core\Render\Element\ElementInterface::getInfo()
*/
......@@ -55,7 +53,7 @@ public function getInfo($type);
* Retrieves a single property for the defined element type.
*
* @param string $type
* An element type as defined by hook_element_info().
* An element type as defined by an element plugin.
* @param string $property_name
* The property within the element type that should be returned.
* @param $default
......
......@@ -148,7 +148,7 @@ public function renderPlain(&$elements);
* $pre_bubbling_cid.
* - If this element has #type defined and the default attributes for this
* element have not already been merged in (#defaults_loaded = TRUE) then
* the defaults for this type of element, defined in hook_element_info(),
* the defaults for this type of element, defined by an element plugin,
* are merged into the array. #defaults_loaded is set by functions that
* process render arrays and call the element info service before passing
* the array to Renderer::render(), such as form_builder() in the Form
......
......@@ -294,10 +294,7 @@
* on plugins, and look for classes with the RenderElement or FormElement
* annotation to discover what render elements are available.
*
* Modules can also currently define render elements by implementing
* hook_element_info(), although defining a plugin is preferred.
* properties. Look through implementations of hook_element_info() to discover
* elements defined this way.
* Modules can define render elements by defining an element plugin.
*
* @section sec_caching Caching
* The Drupal rendering process has the ability to cache rendered output at any
......@@ -690,32 +687,6 @@ function hook_render_template($template_file, $variables) {
return $twig_service->loadTemplate($template_file)->render($variables);
}
/**
* Allows modules to declare their own Form API element types and specify their
* default values.
*
* This hook allows modules to declare their own form element types and to
* specify their default values. The values returned by this hook will be
* merged with the elements returned by form constructor implementations and so
* can return defaults for any Form APIs keys in addition to those explicitly
* documented by \Drupal\Core\Render\ElementInfoManagerInterface::getInfo().
*
* @return array
* An associative array with structure identical to that of the return value
* of \Drupal\Core\Render\ElementInfoManagerInterface::getInfo().
*
* @deprecated Use an annotated class instead, see
* \Drupal\Core\Render\Element\ElementInterface.
*
* @see hook_element_info_alter()
*/
function hook_element_info() {
$types['filter_format'] = array(
'#input' => TRUE,
);
return $types;
}
/**
* Alter the element type information returned from modules.
*
......@@ -726,7 +697,8 @@ function hook_element_info() {
* An associative array with structure identical to that of the return value
* of \Drupal\Core\Render\ElementInfoManagerInterface::getInfo().
*
* @see hook_element_info()
* @see \Drupal\Core\Render\ElementInfoManager
* @see \Drupal\Core\Render\Element\ElementInterface
*/
function hook_element_info_alter(array &$types) {
// Decrease the default size of textfields.
......
......@@ -29,7 +29,6 @@
* @see hook_contextual_links_alter()
* @see hook_contextual_links_plugins_alter()
* @see contextual_pre_render_links()
* @see contextual_element_info()
*/
function hook_contextual_links_view_alter(&$element, $items) {
// Add another class to all contextual link lists to facilitate custom
......
......@@ -58,7 +58,7 @@ function editor_menu_links_discovered_alter(array &$links) {
* module), so that selecting a text format notifies a client-side text editor
* when it should be enabled or disabled.
*
* @see filter_element_info()
* @see \Drupal\filter\Element\TextFormat
*/
function editor_element_info_alter(&$types) {
$types['text_format']['#pre_render'][] = 'element.editor:preRenderTextFormat';
......
......@@ -678,9 +678,6 @@ public function multistepAjax($form, FormStateInterface $form_state) {
/**
* Performs pre-render tasks on field_ui_table elements.
*
* This function is assigned as a #pre_render callback in
* field_ui_element_info().
*
* @param array $elements
* A structured array containing two sub-levels of elements. Properties
* used:
......@@ -688,6 +685,8 @@ public function multistepAjax($form, FormStateInterface $form_state) {
* drupal_attach_tabledrag(). The HTML ID of the table is added to each
* $options array.
*
* @return array
*
* @see drupal_render()
* @see \Drupal\Core\Render\Element\Table::preRenderTable()
*/
......
......@@ -66,101 +66,6 @@ protected function setUp() {
$this->elementInfo = new ElementInfoManager(new \ArrayObject(), $this->cache, $this->cacheTagsInvalidator, $this->moduleHandler, $this->themeManager);
}
/**
* Tests the getInfo method.
*
* @covers ::getInfo
* @covers ::buildInfo
*
* @dataProvider providerTestGetInfo
*/
public function testGetInfo($type, $expected_info, $element_info, callable $alter_callback = NULL) {
$this->moduleHandler->expects($this->once())
->method('invokeAll')
->with('element_info')
->will($this->returnValue($element_info));
$this->moduleHandler->expects($this->once())
->method('alter')
->with('element_info', $this->anything())
->will($this->returnCallback($alter_callback ?: function($info) {
return $info;
}));
$this->themeManager->expects($this->once())
->method('getActiveTheme')
->willReturn(new ActiveTheme(['name' => 'test']));
$this->themeManager->expects($this->once())
->method('alter')
->with('element_info', $this->anything())
->will($this->returnCallback($alter_callback ?: function($info) {
return $info;
}));
$this->cache->expects($this->at(0))
->method('get')
->with('element_info_build:test')
->will($this->returnValue(FALSE));
$this->cache->expects($this->at(1))
->method('get')
->with('element_info')
->will($this->returnValue(FALSE));
$this->cache->expects($this->at(2))
->method('set')
->with('element_info');
$this->cache->expects($this->at(3))
->method('set')
->with('element_info_build:test');
$this->assertEquals($expected_info, $this->elementInfo->getInfo($type));
}
/**
* Provides tests data for getInfo.
*
* @return array
*/
public function providerTestGetInfo() {
$data = array();
// Provide an element and expect it is returned.
$data[] = array(
'page',
array(
'#type' => 'page',
'#theme' => 'page',
'#defaults_loaded' => TRUE,
),
array('page' => array(
'#theme' => 'page',
)),
);
// Provide an element but request an non existent one.
$data[] = array(
'form',
array(
'#defaults_loaded' => TRUE,
),
array('page' => array(
'#theme' => 'page',
)),
);
// Provide an element and alter it to ensure it is altered.
$data[] = array(
'page',
array(
'#type' => 'page',
'#theme' => 'page',
'#number' => 597219,
'#defaults_loaded' => TRUE,
),
array('page' => array(
'#theme' => 'page',
)),
function ($alter_name, array &$info) {
$info['page']['#number'] = 597219;
}
);
return $data;
}
/**
* Tests the getInfo() method when render element plugins are used.
*
......@@ -170,10 +75,6 @@ function ($alter_name, array &$info) {
* @dataProvider providerTestGetInfoElementPlugin
*/
public function testGetInfoElementPlugin($plugin_class, $expected_info) {
$this->moduleHandler->expects($this->once())
->method('invokeAll')
->with('element_info')
->willReturn(array());
$this->moduleHandler->expects($this->once())
->method('alter')
->with('element_info', $this->anything())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment