Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
226 / 226 |
|
100.00% |
34 / 34 |
CRAP | n/a |
0 / 0 |
|
| name_help | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| name_name_widget_layouts | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| name_theme | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| template_preprocess_name_item | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
4 | |||
| template_preprocess_name_item_list | |
100.00% |
37 / 37 |
|
100.00% |
1 / 1 |
8 | |||
| name_user_format_name_alter | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| name_user_load | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| name_user_save | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| name_field_config_create | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| name_field_config_delete | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| name_module_implements_alter | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| name_token_info_alter | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| name_tokens | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 | |||
| name_tokens_alter | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |||
| name_field_views_data | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| name_field_type_category_info_alter | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| _name_translations | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| _name_component_keys | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| _name_formatter_output_types | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| _name_component_layout | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| _name_formatter_output_options | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| name_widget_layouts | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| name_user_format_name_alter_preload | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| name_get_additional_component | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| name_get_custom_format_options | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| name_get_custom_list_format_options | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| name_get_format_by_machine_name | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| name_element_expand | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| name_element_render_component | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| name_component_description_after_build_label_alter | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| name_element_validate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| name_element_pre_render | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| name_element_validate_is_empty | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| _name_value_sanitize | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @file |
| 5 | * Defines an API for displaying and inputting names. |
| 6 | * |
| 7 | * @todo Make sure that all labels are based on the _name_translations() |
| 8 | * function and use a name:: prefix. This can be parsed out here to allow |
| 9 | * string overrides to work and to integrate with i18n too. |
| 10 | * t('@name_given', ['@name_given' => t('Given')]) |
| 11 | */ |
| 12 | |
| 13 | use Drupal\Component\Utility\Html; |
| 14 | use Drupal\Core\Entity\EntityTypeManagerInterface; |
| 15 | use Drupal\Core\Field\FieldItemListInterface; |
| 16 | use Drupal\Core\Form\FormStateInterface; |
| 17 | use Drupal\Core\Hook\Attribute\LegacyHook; |
| 18 | use Drupal\Core\Render\BubbleableMetadata; |
| 19 | use Drupal\Core\Render\RendererInterface; |
| 20 | use Drupal\Core\Routing\RouteMatchInterface; |
| 21 | use Drupal\Core\Session\AccountInterface; |
| 22 | use Drupal\field\FieldConfigInterface; |
| 23 | use Drupal\field\FieldStorageConfigInterface; |
| 24 | use Drupal\name\Element\Name; |
| 25 | use Drupal\name\Hook\FieldConfigHooks; |
| 26 | use Drupal\name\Hook\FieldHooks; |
| 27 | use Drupal\name\Hook\HelpHooks; |
| 28 | use Drupal\name\Hook\ThemeHooks; |
| 29 | use Drupal\name\Hook\TokenHooks; |
| 30 | use Drupal\name\Hook\UserHooks; |
| 31 | use Drupal\name\Hook\WidgetLayoutHooks; |
| 32 | use Drupal\name\Service\FormatOptionService; |
| 33 | use Drupal\name\Utility\NameComponents; |
| 34 | use Drupal\user\UserInterface; |
| 35 | use Symfony\Component\DependencyInjection\ContainerInterface; |
| 36 | |
| 37 | /** |
| 38 | * Legacy FQCNs for moved classes. |
| 39 | * |
| 40 | * Canonical types live in Drupal\name\Service or Drupal\name\Utility. |
| 41 | * |
| 42 | * @see \Drupal\name\Service\NameFormatterInterface |
| 43 | * @see \Drupal\name\Service\GeneratorInterface |
| 44 | * @see \Drupal\name\Service\AutocompleteService |
| 45 | * @see \Drupal\name\Service\NameOptionService |
| 46 | * @see \Drupal\name\Service\NameFormatParserService |
| 47 | * @see \Drupal\name\Service\NameFormatterService |
| 48 | * @see \Drupal\name\Service\GeneratorService |
| 49 | * @see \Drupal\name\Controller\AutocompleteController |
| 50 | * @see \Drupal\name\Utility\UnicodeExtras |
| 51 | * @see \Drupal\name\Access\NameFormatAccessHandler |
| 52 | * @see \Drupal\name\Entity\NameFormatInterface |
| 53 | * @see \Drupal\name\Entity\NameListFormatInterface |
| 54 | * @see \Drupal\name\Form\NameSettingsForm |
| 55 | * @see \Drupal\name\ListBuilder\NameFormatListBuilder |
| 56 | * @see \Drupal\name\ListBuilder\NameListFormatListBuilder |
| 57 | */ |
| 58 | class_alias('Drupal\name\Service\NameFormatterInterface', 'Drupal\name\NameFormatterInterface'); |
| 59 | class_alias('Drupal\name\Service\GeneratorInterface', 'Drupal\name\NameGeneratorInterface'); |
| 60 | class_alias('Drupal\name\Service\AutocompleteService', 'Drupal\name\NameAutocomplete'); |
| 61 | class_alias('Drupal\name\Service\NameOptionService', 'Drupal\name\NameOptionsProvider'); |
| 62 | class_alias('Drupal\name\Service\NameFormatParserService', 'Drupal\name\NameFormatParser'); |
| 63 | class_alias('Drupal\name\Service\NameFormatterService', 'Drupal\name\NameFormatter'); |
| 64 | class_alias('Drupal\name\Service\GeneratorService', 'Drupal\name\NameGenerator'); |
| 65 | class_alias('Drupal\name\Controller\AutocompleteController', 'Drupal\name\Controller\NameAutocompleteController'); |
| 66 | class_alias('Drupal\name\Utility\UnicodeExtras', 'Drupal\name\NameUnicodeExtras'); |
| 67 | class_alias('Drupal\name\Access\NameFormatAccessHandler', 'Drupal\name\NameFormatAccessController'); |
| 68 | class_alias('Drupal\name\Entity\NameFormatInterface', 'Drupal\name\NameFormatInterface'); |
| 69 | class_alias('Drupal\name\Entity\NameListFormatInterface', 'Drupal\name\NameListFormatInterface'); |
| 70 | class_alias('Drupal\name\Form\SettingsForm', 'Drupal\name\NameSettingsForm'); |
| 71 | class_alias('Drupal\name\ListBuilder\NameFormatListBuilder', 'Drupal\name\NameFormatListBuilder'); |
| 72 | class_alias('Drupal\name\ListBuilder\NameListFormatListBuilder', 'Drupal\name\NameListFormatListBuilder'); |
| 73 | |
| 74 | /** |
| 75 | * Implements hook_help(). |
| 76 | */ |
| 77 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 78 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 79 | function name_help($route_name, RouteMatchInterface $route_match) { |
| 80 | $help = \Drupal::getContainer()->get( |
| 81 | HelpHooks::class, |
| 82 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 83 | ); |
| 84 | if ($help === NULL) { |
| 85 | return []; |
| 86 | } |
| 87 | return $help->help($route_name, $route_match); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Implements hook_name_widget_layouts(). |
| 92 | */ |
| 93 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 94 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 95 | function name_name_widget_layouts() { |
| 96 | $widget = \Drupal::getContainer()->get( |
| 97 | WidgetLayoutHooks::class, |
| 98 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 99 | ); |
| 100 | if ($widget === NULL) { |
| 101 | return []; |
| 102 | } |
| 103 | return $widget->nameWidgetLayouts(); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Implements hook_theme(). |
| 108 | */ |
| 109 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 110 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 111 | function name_theme() { |
| 112 | $theme = \Drupal::getContainer()->get( |
| 113 | ThemeHooks::class, |
| 114 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 115 | ); |
| 116 | if ($theme === NULL) { |
| 117 | return []; |
| 118 | } |
| 119 | return $theme->theme(); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Prepares variables for name_item template. |
| 124 | * |
| 125 | * Default template: name-item.html.twig. |
| 126 | * |
| 127 | * @param array $variables |
| 128 | * An associative array containing: |
| 129 | * - item: Keyed array of name components. |
| 130 | * - format: The machine name of the format. |
| 131 | * - settings: Additional settings to control the parser. |
| 132 | */ |
| 133 | function template_preprocess_name_item(array &$variables) { |
| 134 | $variables['settings'] += [ |
| 135 | 'markup' => 0, |
| 136 | ]; |
| 137 | $format_options = \Drupal::getContainer() |
| 138 | ->get('name.format_options', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
| 139 | $format = ''; |
| 140 | if ($format_options) { |
| 141 | $format_id = FormatOptionService::normalizeLegacyFormatMachineName( |
| 142 | $variables['format'] ?? NULL, |
| 143 | ); |
| 144 | if ($format_id !== NULL) { |
| 145 | $format = $format_options->getFormatPatternByMachineName($format_id); |
| 146 | } |
| 147 | if (empty($format)) { |
| 148 | $format = $format_options->getFormatPatternByMachineName('default'); |
| 149 | } |
| 150 | } |
| 151 | $variables['formatted_name'] = \Drupal::service('name.format_parser') |
| 152 | ->parse($variables['item'], $format, $variables['settings']); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Prepares variables for name_item_list template. |
| 157 | * |
| 158 | * Default template: name-item-list.html.twig. |
| 159 | * Note: This function expects a list of sanitized name items. |
| 160 | * |
| 161 | * @param array $variables |
| 162 | * An associative array containing: |
| 163 | * - items: Keyed array of name components. |
| 164 | * - format: The machine name of the format. |
| 165 | * - settings: Additional settings to control the parser. |
| 166 | */ |
| 167 | function template_preprocess_name_item_list(array &$variables) { |
| 168 | $items = $variables['items']; |
| 169 | $variables['original_count'] = count($items); |
| 170 | if ($variables['original_count'] == 1) { |
| 171 | $variables['item'] = array_pop($items); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | $settings = $variables['settings']; |
| 176 | $settings += [ |
| 177 | // default, plain, or raw. |
| 178 | 'output' => 'default', |
| 179 | 'multiple_delimiter' => ', ', |
| 180 | // And or symbol. |
| 181 | 'multiple_and' => 'text', |
| 182 | // contextual, always, never. |
| 183 | 'multiple_delimiter_precedes_last' => 'never', |
| 184 | 'multiple_el_al_min' => 3, |
| 185 | 'multiple_el_al_first' => 1, |
| 186 | ]; |
| 187 | $variables['settings'] = $settings; |
| 188 | $variables['delimiter'] = $settings['multiple_delimiter']; |
| 189 | if ($settings['output'] == 'default') { |
| 190 | $variables['etal'] = t('<em>et al</em>', [], ['context' => 'name']); |
| 191 | $variables['delimiter'] = Html::escape($variables['delimiter']); |
| 192 | } |
| 193 | else { |
| 194 | $variables['etal'] = t('et al', [], ['context' => 'name']); |
| 195 | if ($settings['output'] == 'plain') { |
| 196 | $variables['delimiter'] = strip_tags($variables['delimiter']); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | if ($variables['original_count'] > $settings['multiple_el_al_min']) { |
| 201 | $limit = min([ |
| 202 | $settings['multiple_el_al_min'], |
| 203 | $settings['multiple_el_al_first'], |
| 204 | ]); |
| 205 | $items = array_slice($items, 0, $limit); |
| 206 | $variables['items_count'] = count($items); |
| 207 | if ($variables['items_count'] == 1) { |
| 208 | $variables['name'] = $items[0]; |
| 209 | } |
| 210 | else { |
| 211 | $variables['names'] = implode($variables['delimiter'] . ' ', $items); |
| 212 | } |
| 213 | } |
| 214 | else { |
| 215 | $variables['lastname'] = array_pop($items); |
| 216 | $variables['names'] = implode($variables['delimiter'] . ' ', $items); |
| 217 | if ($settings['multiple_and'] == 'text') { |
| 218 | $variables['and_'] = t('and', [], ['context' => 'name']); |
| 219 | } |
| 220 | else { |
| 221 | $variables['and_'] = $settings['output'] == 'default' ? '&' : '&'; |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Implements hook_user_format_name_alter(). |
| 228 | */ |
| 229 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 230 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 231 | function name_user_format_name_alter(&$name, AccountInterface $account) { |
| 232 | $user = \Drupal::getContainer()->get( |
| 233 | UserHooks::class, |
| 234 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 235 | ); |
| 236 | if ($user === NULL) { |
| 237 | return; |
| 238 | } |
| 239 | $user->userFormatNameAlter($name, $account); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Implements hook_user_load(). |
| 244 | */ |
| 245 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 246 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 247 | function name_user_load(array $users) { |
| 248 | $user = \Drupal::getContainer()->get( |
| 249 | UserHooks::class, |
| 250 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 251 | ); |
| 252 | if ($user === NULL) { |
| 253 | return; |
| 254 | } |
| 255 | $user->userLoad($users); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Implements hook_user_save(). |
| 260 | */ |
| 261 | function name_user_save(UserInterface $entity) { |
| 262 | $names = &drupal_static('name_user_realname_cache', []); |
| 263 | unset($names[$entity->id()]); |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Implements hook_ENTITY_TYPE_create() for field_config entities. |
| 268 | */ |
| 269 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 270 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 271 | function name_field_config_create(FieldConfigInterface $entity) { |
| 272 | $fieldConfig = \Drupal::getContainer()->get( |
| 273 | FieldConfigHooks::class, |
| 274 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 275 | ); |
| 276 | if ($fieldConfig === NULL) { |
| 277 | return; |
| 278 | } |
| 279 | $fieldConfig->fieldConfigCreate($entity); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Implements hook_ENTITY_TYPE_delete() for field_config entities. |
| 284 | */ |
| 285 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 286 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 287 | function name_field_config_delete(FieldConfigInterface $entity) { |
| 288 | $fieldConfig = \Drupal::getContainer()->get( |
| 289 | FieldConfigHooks::class, |
| 290 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 291 | ); |
| 292 | if ($fieldConfig === NULL) { |
| 293 | return; |
| 294 | } |
| 295 | $fieldConfig->fieldConfigDelete($entity); |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Implements hook_module_implements_alter(). |
| 300 | * |
| 301 | * Runs hook_token_info_alter() for this module after the Token module so field |
| 302 | * chain metadata (the subtree with given, family, etc.) is already present when |
| 303 | * we attach the Formatted branch. |
| 304 | */ |
| 305 | function name_module_implements_alter(array &$implementations, string $hook): void { |
| 306 | if ($hook !== 'token_info_alter' || !isset($implementations['name'])) { |
| 307 | return; |
| 308 | } |
| 309 | $group = $implementations['name']; |
| 310 | unset($implementations['name']); |
| 311 | $implementations['name'] = $group; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Implements hook_token_info_alter(). |
| 316 | */ |
| 317 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 318 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 319 | function name_token_info_alter(array &$info): void { |
| 320 | $token = \Drupal::getContainer()->get( |
| 321 | TokenHooks::class, |
| 322 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 323 | ); |
| 324 | if ($token === NULL) { |
| 325 | return; |
| 326 | } |
| 327 | $token->alterTokenInfo($info); |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Implements hook_tokens(). |
| 332 | */ |
| 333 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 334 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 335 | function name_tokens( |
| 336 | string $type, |
| 337 | array $tokens, |
| 338 | array $data, |
| 339 | array $options, |
| 340 | BubbleableMetadata $bubbleable_metadata, |
| 341 | ): array { |
| 342 | $token = \Drupal::getContainer()->get( |
| 343 | TokenHooks::class, |
| 344 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 345 | ); |
| 346 | if ($token === NULL) { |
| 347 | return []; |
| 348 | } |
| 349 | return $token->getChainReplacements( |
| 350 | $type, |
| 351 | $tokens, |
| 352 | $data, |
| 353 | $options, |
| 354 | $bubbleable_metadata, |
| 355 | ); |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Implements hook_tokens_alter(). |
| 360 | */ |
| 361 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 362 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 363 | function name_tokens_alter( |
| 364 | array &$replacements, |
| 365 | array $context, |
| 366 | BubbleableMetadata $bubbleable_metadata, |
| 367 | ): void { |
| 368 | $token = \Drupal::getContainer()->get( |
| 369 | TokenHooks::class, |
| 370 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 371 | ); |
| 372 | if ($token === NULL) { |
| 373 | return; |
| 374 | } |
| 375 | $token->alterReplacements( |
| 376 | $replacements, |
| 377 | $context, |
| 378 | $bubbleable_metadata, |
| 379 | ); |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Implements hook_field_views_data(). |
| 384 | */ |
| 385 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 386 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 387 | function name_field_views_data(FieldStorageConfigInterface $field_storage) { |
| 388 | $field = \Drupal::getContainer()->get( |
| 389 | FieldHooks::class, |
| 390 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 391 | ); |
| 392 | if ($field === NULL) { |
| 393 | return []; |
| 394 | } |
| 395 | return $field->fieldViewsData($field_storage); |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Implements hook_field_type_category_info_alter(). |
| 400 | */ |
| 401 | // phpcs:ignore Drupal.Commenting.PostStatementComment.Found -- #[LegacyHook] is a PHP attribute, not a trailing comment. |
| 402 | #[LegacyHook] // @phpstan-ignore attribute.notFound |
| 403 | function name_field_type_category_info_alter(&$definitions) { |
| 404 | $field = \Drupal::getContainer()->get( |
| 405 | FieldHooks::class, |
| 406 | ContainerInterface::NULL_ON_INVALID_REFERENCE, |
| 407 | ); |
| 408 | if ($field === NULL) { |
| 409 | return; |
| 410 | } |
| 411 | $field->fieldTypeCategoryInfoAlter($definitions); |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Static cache to reuse translated name components. |
| 416 | * |
| 417 | * These have double encoding to allow easy and targeted string overrides. |
| 418 | * |
| 419 | * @param string[]|null $intersect |
| 420 | * An array of field component keys of the translations required. |
| 421 | * |
| 422 | * @return array |
| 423 | * Keyed array of the field component labels. |
| 424 | * |
| 425 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 426 | * \Drupal::service('name.component_metadata')->getTranslations() instead. |
| 427 | * |
| 428 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 429 | */ |
| 430 | function _name_translations(?array $intersect = NULL) { |
| 431 | @trigger_error('_name_translations() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal::service(\'name.component_metadata\')->getTranslations() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 432 | $metadata = \Drupal::getContainer() |
| 433 | ->get('name.component_metadata', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
| 434 | return $metadata ? $metadata->getTranslations($intersect) : []; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Defines the component keys. |
| 439 | * |
| 440 | * @return string[] |
| 441 | * An array of the core field component columns. |
| 442 | * |
| 443 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 444 | * \Drupal\name\Utility\NameComponents::coreKeys() instead. |
| 445 | * |
| 446 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 447 | */ |
| 448 | function _name_component_keys() { |
| 449 | @trigger_error('_name_component_keys() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal\name\Utility\NameComponents::coreKeys() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 450 | return NameComponents::coreKeys(); |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Private helper function to define the formatter rendering methods. |
| 455 | * |
| 456 | * @return array |
| 457 | * Keyed formatter output type labels. |
| 458 | * |
| 459 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 460 | * \Drupal::service('name.component_metadata')->getFormatterOutputTypes() |
| 461 | * instead. |
| 462 | * |
| 463 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 464 | */ |
| 465 | function _name_formatter_output_types() { |
| 466 | @trigger_error('_name_formatter_output_types() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal::service(\'name.component_metadata\')->getFormatterOutputTypes() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 467 | $service = \Drupal::getContainer() |
| 468 | ->get('name.component_metadata', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
| 469 | return $service ? $service->getFormatterOutputTypes() : []; |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Sorts the widgets according to the language type. |
| 474 | * |
| 475 | * @param array $element |
| 476 | * A name sub-element render array. |
| 477 | * @param string $layout |
| 478 | * Layout machine name. |
| 479 | * |
| 480 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 481 | * \Drupal\name\Utility\NameComponents::applyLayout() instead. |
| 482 | * |
| 483 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 484 | */ |
| 485 | function _name_component_layout(&$element, $layout = 'default') { |
| 486 | @trigger_error('_name_component_layout() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal\name\Utility\NameComponents::applyLayout() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 487 | NameComponents::applyLayout($element, $layout); |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * Helper function to define the available output formatter options. |
| 492 | * |
| 493 | * @return array |
| 494 | * Keyed formatter output option labels. |
| 495 | * |
| 496 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 497 | * \Drupal::service('name.component_metadata')->getFormatterOutputOptions() |
| 498 | * instead. |
| 499 | * |
| 500 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 501 | */ |
| 502 | function _name_formatter_output_options() { |
| 503 | @trigger_error('_name_formatter_output_options() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal::service(\'name.component_metadata\')->getFormatterOutputOptions() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 504 | $service = \Drupal::getContainer() |
| 505 | ->get('name.component_metadata', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
| 506 | return $service ? $service->getFormatterOutputOptions() : []; |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Helper function to get any defined name widget layout options. |
| 511 | * |
| 512 | * @return array |
| 513 | * Keyed array of the name widget layout options. |
| 514 | * |
| 515 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 516 | * \Drupal::service('name.widget_layouts')->getLayouts() instead. |
| 517 | * |
| 518 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 519 | */ |
| 520 | function name_widget_layouts() { |
| 521 | @trigger_error('name_widget_layouts() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal::service(\'name.widget_layouts\')->getLayouts() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 522 | $service = \Drupal::getContainer()->get('name.widget_layouts', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
| 523 | return $service ? $service->getLayouts() : []; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * Internal helper function to load the user account if required. |
| 528 | * |
| 529 | * Recursion check in place after RealName module issue queue suggested that |
| 530 | * there were issues with token based recursion on load. |
| 531 | * |
| 532 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 533 | * \Drupal::service('name.user_realname_preload')->preload() instead. |
| 534 | * |
| 535 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 536 | */ |
| 537 | function name_user_format_name_alter_preload($account) { |
| 538 | @trigger_error('name_user_format_name_alter_preload() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal::service(\'name.user_realname_preload\')->preload() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 539 | $preload = \Drupal::getContainer() |
| 540 | ->get('name.user_realname_preload', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
| 541 | if ($preload) { |
| 542 | $preload->preload($account); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * Helper function to an additional component for an item. |
| 548 | * |
| 549 | * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
| 550 | * The entity type manager to generate the view. |
| 551 | * @param \Drupal\Core\Render\RendererInterface $renderer |
| 552 | * The renderer to render the value. |
| 553 | * @param \Drupal\Core\Field\FieldItemListInterface $items |
| 554 | * The items to render. |
| 555 | * @param string $key_value |
| 556 | * The key value. |
| 557 | * @param string $sep_value |
| 558 | * The separator value to use when handling multiple values. |
| 559 | * |
| 560 | * @return string |
| 561 | * The value of the additional component. |
| 562 | * |
| 563 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 564 | * \Drupal::service('name.additional_component')->getAdditionalComponent() |
| 565 | * instead. The entity type manager and renderer arguments are ignored. |
| 566 | * |
| 567 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 568 | */ |
| 569 | function name_get_additional_component(EntityTypeManagerInterface $entityTypeManager, RendererInterface $renderer, FieldItemListInterface $items, $key_value, $sep_value) { |
| 570 | @trigger_error('name_get_additional_component() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal::service(\'name.additional_component\')->getAdditionalComponent() instead. The entity type manager and renderer arguments are ignored. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 571 | $service = \Drupal::getContainer() |
| 572 | ->get('name.additional_component', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
| 573 | return $service ? $service->getAdditionalComponent($items, $key_value, $sep_value) : ''; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * Helper function to generate a list of all defined custom formatting options. |
| 578 | * |
| 579 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 580 | * \Drupal::service('name.format_options')->getCustomFormatOptions() instead. |
| 581 | * |
| 582 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 583 | */ |
| 584 | function name_get_custom_format_options() { |
| 585 | @trigger_error('name_get_custom_format_options() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal::service(\'name.format_options\')->getCustomFormatOptions() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 586 | $service = \Drupal::getContainer() |
| 587 | ->get('name.format_options', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
| 588 | return $service ? $service->getCustomFormatOptions() : []; |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * Helper function to generate a list of all defined custom formatting options. |
| 593 | * |
| 594 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 595 | * \Drupal::service('name.format_options')->getCustomListFormatOptions() |
| 596 | * instead. |
| 597 | * |
| 598 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 599 | */ |
| 600 | function name_get_custom_list_format_options() { |
| 601 | @trigger_error('name_get_custom_list_format_options() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal::service(\'name.format_options\')->getCustomListFormatOptions() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 602 | $service = \Drupal::getContainer() |
| 603 | ->get('name.format_options', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
| 604 | return $service ? $service->getCustomListFormatOptions() : []; |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * Loads a format based on the machine name. |
| 609 | * |
| 610 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 611 | * \Drupal::service('name.format_options')->getFormatPatternByMachineName() |
| 612 | * instead. |
| 613 | * |
| 614 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 615 | */ |
| 616 | function name_get_format_by_machine_name($machine_name) { |
| 617 | @trigger_error('name_get_format_by_machine_name() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal::service(\'name.format_options\')->getFormatPatternByMachineName() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 618 | $id = FormatOptionService::normalizeLegacyFormatMachineName($machine_name); |
| 619 | if ($id === NULL) { |
| 620 | return NULL; |
| 621 | } |
| 622 | $service = \Drupal::getContainer() |
| 623 | ->get('name.format_options', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
| 624 | return $service ? $service->getFormatPatternByMachineName($id) : NULL; |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * The #process callback to create the element. |
| 629 | * |
| 630 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 631 | * Drupal\name\Element\Name::process() instead. |
| 632 | * |
| 633 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 634 | */ |
| 635 | function name_element_expand($element, &$form_state, $complete_form) { |
| 636 | @trigger_error('name_element_expand() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal\name\Element\Name::process() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 637 | return Name::process($element, $form_state, $complete_form); |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Helper function to render a component within a name element. |
| 642 | * |
| 643 | * @param array $components |
| 644 | * Core properties for all components. |
| 645 | * @param string $component_key |
| 646 | * The component key of the component that is being rendered. |
| 647 | * @param array $base_element |
| 648 | * Base FAPI element that makes up a name element. |
| 649 | * @param bool $core |
| 650 | * Flag that indicates that the component is required as part of a valid |
| 651 | * name. |
| 652 | * |
| 653 | * @return array |
| 654 | * The constructed component FAPI structure for a name element. |
| 655 | * |
| 656 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 657 | * Drupal\name\Element\Name::renderComponent() instead. |
| 658 | * |
| 659 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 660 | */ |
| 661 | function name_element_render_component(array $components, $component_key, array $base_element, $core) { |
| 662 | @trigger_error('name_element_render_component() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal\name\Element\Name::renderComponent() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 663 | return Name::renderComponent($components, $component_key, $base_element, $core); |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * After build for setting the correct ID on the description labels. |
| 668 | * |
| 669 | * @param array $element |
| 670 | * The form element that needs the for attribute set. |
| 671 | * @param \Drupal\Core\Form\FormStateInterface $form_state |
| 672 | * The current state of the form. |
| 673 | * |
| 674 | * @return array |
| 675 | * The form element. |
| 676 | * |
| 677 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 678 | * Drupal\name\Element\Name::componentDescriptionAfterBuildLabelAlter() |
| 679 | * instead. |
| 680 | * |
| 681 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 682 | */ |
| 683 | function name_component_description_after_build_label_alter(array $element, FormStateInterface $form_state) { |
| 684 | @trigger_error('name_component_description_after_build_label_alter() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal\name\Element\Name::componentDescriptionAfterBuildLabelAlter() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 685 | return Name::componentDescriptionAfterBuildLabelAlter($element, $form_state); |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * A custom validator to check the components of a name element. |
| 690 | * |
| 691 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 692 | * Drupal\name\Element\Name::validateElement() or the |
| 693 | * name.element_validator service instead. |
| 694 | * |
| 695 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 696 | */ |
| 697 | function name_element_validate($element, &$form_state) { |
| 698 | @trigger_error('name_element_validate() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal\name\Element\Name::validateElement() or the name.element_validator service instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 699 | return Name::validateElement($element, $form_state); |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * This function themes the element and controls the title display. |
| 704 | * |
| 705 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. |
| 706 | * Use Drupal\name\Element\Name::preRender() instead. |
| 707 | * @see https://www.drupal.org/project/name/issues/3128409 |
| 708 | */ |
| 709 | function name_element_pre_render($element) { |
| 710 | @trigger_error('name_element_pre_render() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal\name\Element\Name::preRender() instead. See https://www.drupal.org/project/name/issues/3128409', E_USER_DEPRECATED); |
| 711 | return Name::preRender($element); |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * Check if the name element is empty or not. |
| 716 | * |
| 717 | * @param array $item |
| 718 | * The name element. |
| 719 | * |
| 720 | * @return bool |
| 721 | * TRUE if $item not to contain any data; FALSE otherwise. |
| 722 | * |
| 723 | * @group validation |
| 724 | * |
| 725 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 726 | * Drupal\name\Element\Name::validateIsEmpty() instead. |
| 727 | * |
| 728 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 729 | */ |
| 730 | function name_element_validate_is_empty(array $item) { |
| 731 | @trigger_error('name_element_validate_is_empty() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal\name\Element\Name::validateIsEmpty() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 732 | return Name::validateIsEmpty($item); |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Helper function to sanitize a name component or name string. |
| 737 | * |
| 738 | * @param mixed $item |
| 739 | * If this is a string, then the processing happens on this. |
| 740 | * If this is an array, the processing happens on the column index. |
| 741 | * @param string|null $column |
| 742 | * The item column to look at. |
| 743 | * @param string $type |
| 744 | * Tells the function how to handle the text processing: |
| 745 | * 'default' runs through check_plain() |
| 746 | * 'plain' runs through strip_tags() |
| 747 | * 'raw' has no processing applied to it. |
| 748 | * |
| 749 | * @return string |
| 750 | * Sanitized string (depending on type specified). |
| 751 | * |
| 752 | * @deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use |
| 753 | * \Drupal\name\Utility\NameComponents::sanitizeValue() instead. |
| 754 | * |
| 755 | * @see https://www.drupal.org/project/name/issues/3555260 |
| 756 | */ |
| 757 | function _name_value_sanitize($item, $column = NULL, $type = 'default') { |
| 758 | @trigger_error('_name_value_sanitize() is deprecated in name:8.x-1.3 and is removed from name:2.0.0. Use \Drupal\name\Utility\NameComponents::sanitizeValue() instead. See https://www.drupal.org/project/name/issues/3555260', E_USER_DEPRECATED); |
| 759 | return NameComponents::sanitizeValue($item, $column, $type); |
| 760 | } |