Issue #2099261 by JulienD, mr.baileys, amateescu: Fixed field_help() no longer lists field_type()/widget modules and can throw undefined index notice.
parent
a34cb25102
commit
0dd4b14fbb
|
@ -120,25 +120,29 @@ function field_help($path, $arg) {
|
||||||
$output .= '<dt>' . t('Enabling field types') . '</dt>';
|
$output .= '<dt>' . t('Enabling field types') . '</dt>';
|
||||||
$output .= '<dd>' . 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 <a href="@modules">Modules administration page</a>. 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 <a href="@contrib">contributed module section of Drupal.org</a>. Currently enabled field and input widget modules:', array('@modules' => url('admin/modules'), '@contrib' => 'http://drupal.org/project/modules', '@options' => url('admin/help/options')));
|
$output .= '<dd>' . 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 <a href="@modules">Modules administration page</a>. 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 <a href="@contrib">contributed module section of Drupal.org</a>. Currently enabled field and input widget modules:', 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, in
|
// Make a list of all widget and field modules currently enabled, ordered
|
||||||
// order by displayed module name (module names are not translated).
|
// by displayed module name (module names are not translated).
|
||||||
$items = array();
|
$items = array();
|
||||||
$info = system_get_info('module');
|
$info = system_get_info('module');
|
||||||
$modules = array_merge(\Drupal::moduleHandler()->getImplementations('field_info'), \Drupal::moduleHandler()->getImplementations('field_widget_info'));
|
$field_widgets = \Drupal::service('plugin.manager.field.widget')->getDefinitions();
|
||||||
|
$field_types = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions();
|
||||||
|
foreach (array_merge($field_types, $field_widgets) as $field_module) {
|
||||||
|
$modules[] = $field_module['provider'];
|
||||||
|
}
|
||||||
$modules = array_unique($modules);
|
$modules = array_unique($modules);
|
||||||
sort($modules);
|
sort($modules);
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
$display = $info[$module]['name'];
|
$display = $info[$module]['name'];
|
||||||
if (\Drupal::moduleHandler()->implementsHook($module, 'help')) {
|
if (\Drupal::moduleHandler()->implementsHook($module, 'help')) {
|
||||||
$items['items'][] = l($display, 'admin/help/' . $module);
|
$items[] = l($display, 'admin/help/' . $module);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$items['items'][] = $display;
|
$items[] = $display;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$item_list = array(
|
$item_list = array(
|
||||||
'#theme' => 'item_list',
|
'#theme' => 'item_list',
|
||||||
'#items' => $items['items'],
|
'#items' => $items,
|
||||||
);
|
);
|
||||||
$output .= drupal_render($item_list);
|
$output .= drupal_render($item_list);
|
||||||
return $output;
|
return $output;
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Definition of Drupal\field\Tests\FieldHelpTest.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\field\Tests;
|
||||||
|
|
||||||
|
use Drupal\simpletest\WebTestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests help display for the Field module.
|
||||||
|
*/
|
||||||
|
class FieldHelpTest extends WebTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules to enable.
|
||||||
|
*
|
||||||
|
* @var array.
|
||||||
|
*/
|
||||||
|
public static $modules = array('field', 'help');
|
||||||
|
|
||||||
|
// Tests field help implementation without optional core modules enabled.
|
||||||
|
protected $profile = 'minimal';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The admin user that will be created.
|
||||||
|
*/
|
||||||
|
protected $adminUser;
|
||||||
|
|
||||||
|
public static function getInfo() {
|
||||||
|
return array(
|
||||||
|
'name' => 'Field help functionality',
|
||||||
|
'description' => 'Verify help display for the Field module.',
|
||||||
|
'group' => 'Field',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
// Create the admin user.
|
||||||
|
$this->adminUser = $this->drupalCreateUser(array('access administration pages', 'view the administration theme'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the Field module's help page.
|
||||||
|
*/
|
||||||
|
public function testFieldHelp() {
|
||||||
|
// Login the admin user.
|
||||||
|
$this->drupalLogin($this->adminUser);
|
||||||
|
|
||||||
|
// Visit the Help page and make sure no warnings or notices are thrown.
|
||||||
|
$this->drupalGet('admin/help/field');
|
||||||
|
|
||||||
|
// Enable the Options, Telephone and E-mail modules.
|
||||||
|
\Drupal::moduleHandler()->install(array('options', 'telephone', 'email'));
|
||||||
|
\Drupal::service('plugin.manager.field.widget')->clearCachedDefinitions();
|
||||||
|
\Drupal::service('plugin.manager.entity.field.field_type')->clearCachedDefinitions();
|
||||||
|
|
||||||
|
$this->drupalGet('admin/help/field');
|
||||||
|
$this->assertLink('Options', 0, 'Options module is listed on the Field help page.');
|
||||||
|
$this->assertLink('E-mail', 0, 'E-mail module is listed on the Field help page.');
|
||||||
|
$this->assertText('Telephone', 'Modules with field types that do not implement hook_help are listed.');
|
||||||
|
$this->assertNoLink('Telephone', 'Modules with field types that do not implement hook_help are not linked.');
|
||||||
|
$this->assertNoLink('Link', 'Modules that have not been installed, are not listed.');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue