class Name in Name Field 8
Provides a name render element.
Plugin annotation
@RenderElement("name");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\name\Element\Name implements TrustedCallbackInterface
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Name
1 file declares its use of Name
- name.module in ./
name.module - Defines an API for displaying and inputing names.
6 string references to 'Name'
- name.schema.yml in config/
schema/ name.schema.yml - config/schema/name.schema.yml
- NameAdminTest::testAdminFormatSettings in tests/
src/ Functional/ NameAdminTest.php - Misc tests related to adding, updating and removing formats.
- NameAdminTest::testAdminListFormatSettings in tests/
src/ Functional/ NameAdminTest.php - Misc tests related to adding, updating and removing formats.
- NameFormatForm::form in src/
Form/ NameFormatForm.php - Gets the actual form array to be built.
- NameListFormatForm::form in src/
Form/ NameListFormatForm.php - Gets the actual form array to be built.
1 #type use of Name
- NameWidget::formElement in src/
Plugin/ Field/ FieldWidget/ NameWidget.php - Returns the form for a single field widget.
File
- src/
Element/ Name.php, line 15
Namespace
Drupal\name\ElementView source
class Name extends FormElement implements TrustedCallbackInterface {
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return [
'preRender',
];
}
/**
* Returns the element properties for this element.
*
* @return array
* An array of element properties. See
* \Drupal\Core\Render\ElementInfoManagerInterface::getInfo() for
* documentation of the standard properties of all elements, and the
* return value format.
*/
public function getInfo() {
$parts = _name_translations();
$field_settings = \Drupal::service('plugin.manager.field.field_type')
->getDefaultFieldSettings('name');
return [
'#input' => TRUE,
'#process' => [
'name_element_expand',
],
'#pre_render' => [
[
__CLASS__,
'preRender',
],
],
'#element_validate' => [
'name_element_validate',
],
'#theme_wrappers' => [
'form_element',
],
'#show_component_required_marker' => 0,
'#default_value' => [
'title' => '',
'given' => '',
'middle' => '',
'family' => '',
'generational' => '',
'credentials' => '',
],
'#minimum_components' => $field_settings['minimum_components'],
'#allow_family_or_given' => $field_settings['allow_family_or_given'],
'#components' => [
'title' => [
'type' => $field_settings['field_type']['title'],
'title' => $parts['title'],
'title_display' => 'description',
'size' => $field_settings['size']['title'],
'maxlength' => $field_settings['max_length']['title'],
'options' => $field_settings['title_options'],
'autocomplete' => FALSE,
],
'given' => [
'type' => 'textfield',
'title' => $parts['given'],
'title_display' => 'description',
'size' => $field_settings['size']['given'],
'maxlength' => $field_settings['max_length']['given'],
'autocomplete' => FALSE,
],
'middle' => [
'type' => 'textfield',
'title' => $parts['middle'],
'title_display' => 'description',
'size' => $field_settings['size']['middle'],
'maxlength' => $field_settings['max_length']['middle'],
'autocomplete' => FALSE,
],
'family' => [
'type' => 'textfield',
'title' => $parts['family'],
'title_display' => 'description',
'size' => $field_settings['size']['family'],
'maxlength' => $field_settings['max_length']['family'],
'autocomplete' => FALSE,
],
'generational' => [
'type' => $field_settings['field_type']['generational'],
'title' => $parts['generational'],
'title_display' => 'description',
'size' => $field_settings['size']['generational'],
'maxlength' => $field_settings['max_length']['generational'],
'options' => $field_settings['generational_options'],
'autocomplete' => FALSE,
],
'credentials' => [
'type' => 'textfield',
'title' => $parts['credentials'],
'title_display' => 'description',
'size' => $field_settings['size']['credentials'],
'maxlength' => $field_settings['max_length']['credentials'],
'autocomplete' => FALSE,
],
],
];
}
/**
* {@inheritdoc}
*/
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
$value = [
'title' => '',
'given' => '',
'middle' => '',
'family' => '',
'generational' => '',
'credentials' => '',
];
if ($input === FALSE) {
$element += [
'#default_value' => [],
];
return $element['#default_value'] + $value;
}
// Throw out all invalid array keys; we only allow pass1 and pass2.
foreach ($value as $allowed_key => $default) {
// These should be strings, but allow other scalars since they might be
// valid input in programmatic form submissions. Any nested array values
// are ignored.
if (isset($input[$allowed_key]) && is_scalar($input[$allowed_key])) {
$value[$allowed_key] = (string) $input[$allowed_key];
}
}
return $value;
}
/**
* This function themes the element and controls the title display.
*/
public static function preRender($element) {
$layouts = name_widget_layouts();
$layout = $layouts['stacked'];
if (!empty($element['#widget_layout']) && isset($layouts[$element['#widget_layout']])) {
$layout = $layouts[$element['#widget_layout']];
}
if (!empty($layout['library'])) {
if (!isset($element['#attached']['library'])) {
$element['#attached']['library'] = [];
}
$element['#attached']['library'] += $layout['library'];
}
$attributes = new Attribute($layout['wrapper_attributes']);
$element['_name'] = [
'#prefix' => '<div' . $attributes . '>',
'#suffix' => '</div>',
];
foreach (_name_translations() as $key => $title) {
if (isset($element[$key])) {
$element['_name'][$key] = $element[$key];
unset($element[$key]);
}
}
if (!empty($element['#component_layout'])) {
_name_component_layout($element['_name'], $element['#component_layout']);
}
return $element;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormElement:: |
public static | function | Adds autocomplete functionality to elements. | |
FormElement:: |
public static | function | #process callback for #pattern form element property. | |
FormElement:: |
public static | function | #element_validate callback for #pattern form element property. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
Name:: |
public | function |
Returns the element properties for this element. Overrides ElementInterface:: |
|
Name:: |
public static | function | This function themes the element and controls the title display. | |
Name:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
Name:: |
public static | function |
Determines how user input is mapped to an element's #value property. Overrides FormElement:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
RenderElement:: |
public static | function | Adds Ajax information about an element to communicate with JavaScript. | |
RenderElement:: |
public static | function | Adds members of this group as actual elements for rendering. | |
RenderElement:: |
public static | function | Form element processing handler for the #ajax form property. | 1 |
RenderElement:: |
public static | function | Arranges elements into groups. | |
RenderElement:: |
public static | function |
Sets a form element's class attribute. Overrides ElementInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |