Commit 32c6ddba authored by MegaChriz's avatar MegaChriz Committed by Alan D.

Issue #3128409 by MegaChriz, ruchi-94, Farnoosh, karishmaamin,...

Issue #3128409 by MegaChriz, ruchi-94, Farnoosh, karishmaamin, abhijeet.kumar2107, Alan D., joshua.boltz, nkoporec, RuslanP, wrd: Drupal 9 compatibilities report
parent cb28e512
...@@ -18,7 +18,9 @@ function name_update_last_removed() { ...@@ -18,7 +18,9 @@ function name_update_last_removed() {
* Upgrade from Drupal 7 to Drupal 8. * Upgrade from Drupal 7 to Drupal 8.
*/ */
function name_update_8001() { function name_update_8001() {
$result = db_query("SELECT * FROM {name_custom_format} ORDER BY name ASC"); $database = \Drupal::database();
$query = $database->query("SELECT * FROM {name_custom_format} ORDER BY name ASC");
$result = $query->fetchAll();
foreach ($result as $row) { foreach ($result as $row) {
\Drupal::config('name_format.' . $row->machine_name) \Drupal::config('name_format.' . $row->machine_name)
...@@ -57,8 +59,7 @@ function name_update_8001() { ...@@ -57,8 +59,7 @@ function name_update_8001() {
variable_del('name_inline_styles_rtl'); variable_del('name_inline_styles_rtl');
variable_del('name_element_wrapper'); variable_del('name_element_wrapper');
variable_del('name_component_required_marker'); variable_del('name_component_required_marker');
$database->schema()->dropTable('name_custom_format');
db_drop_table('name_custom_format');
} }
/** /**
......
...@@ -16,13 +16,13 @@ use Drupal\user\UserInterface; ...@@ -16,13 +16,13 @@ use Drupal\user\UserInterface;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Template\Attribute; use Drupal\Core\Template\Attribute;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Render\RendererInterface; use Drupal\Core\Render\RendererInterface;
use Drupal\name\Element\Name;
/** /**
* Helper function to get any defined name widget layout options. * Helper function to get any defined name widget layout options.
...@@ -120,14 +120,14 @@ function name_user_format_name_alter(&$name, AccountInterface $account) { ...@@ -120,14 +120,14 @@ function name_user_format_name_alter(&$name, AccountInterface $account) {
// Since $account may not be the real User entity object, check the name // Since $account may not be the real User entity object, check the name
// lookup cache for results too. // lookup cache for results too.
if (!isset($account->realname) || !Unicode::strlen($account->realname)) { if (!isset($account->realname) || !mb_strlen($account->realname)) {
$names = &drupal_static('name_user_realname_cache', []); $names = &drupal_static('name_user_realname_cache', []);
if (isset($names[$account->id()])) { if (isset($names[$account->id()])) {
$account->realname = $names[$account->id()]; $account->realname = $names[$account->id()];
} }
} }
if (isset($account->realname) && Unicode::strlen($account->realname)) { if (isset($account->realname) && mb_strlen($account->realname)) {
$name = $account->realname; $name = $account->realname;
} }
} }
...@@ -225,7 +225,8 @@ function name_get_additional_component(EntityTypeManagerInterface $entityTypeMan ...@@ -225,7 +225,8 @@ function name_get_additional_component(EntityTypeManagerInterface $entityTypeMan
} }
} }
} }
catch (\InvalidArgumentException $e) {} catch (\InvalidArgumentException $e) {
}
} }
elseif ($parent->hasField($key_value)) { elseif ($parent->hasField($key_value)) {
$target_items = $parent->get($key_value); $target_items = $parent->get($key_value);
...@@ -255,7 +256,8 @@ function name_get_additional_component(EntityTypeManagerInterface $entityTypeMan ...@@ -255,7 +256,8 @@ function name_get_additional_component(EntityTypeManagerInterface $entityTypeMan
} }
} }
} }
catch (\Exception $e) {} catch (\Exception $e) {
}
} }
break; break;
...@@ -532,7 +534,7 @@ function name_element_render_component(array $components, $component_key, array ...@@ -532,7 +534,7 @@ function name_element_render_component(array $components, $component_key, array
* @return array * @return array
* The form element. * The form element.
*/ */
function name_component_description_after_build_label_alter($element, FormStateInterface $form_state) { function name_component_description_after_build_label_alter(array $element, FormStateInterface $form_state) {
if (!empty($element['#description']) && !empty($element['#id']) && is_array($element['#description'])) { if (!empty($element['#description']) && !empty($element['#id']) && is_array($element['#description'])) {
$element['#description']['#for'] = $element['#id']; $element['#description']['#for'] = $element['#id'];
} }
...@@ -599,38 +601,12 @@ function name_element_validate($element, &$form_state) { ...@@ -599,38 +601,12 @@ function name_element_validate($element, &$form_state) {
/** /**
* This function themes the element and controls the title display. * This function themes the element and controls the title display.
*
* @deprecated in name:8.x-1.0 and is removed from name:2.0.0.
* Use Drupal\name\Element\Name::preRender() instead.
*/ */
function name_element_pre_render($element) { function name_element_pre_render($element) {
$layouts = name_widget_layouts(); return Name::preRender($element);
$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;
} }
/** /**
......
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
* Adds the default list format. * Adds the default list format.
*/ */
function name_post_update_create_name_list_format() { function name_post_update_create_name_list_format() {
$default_list = \Drupal::entityTypeManager()->getStorage('name_list_format')->load('default'); /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $name_list_format_storage */
$name_list_format_storage = \Drupal::entityTypeManager()->getStorage('name_list_format');
$default_list = $name_list_format_storage->load('default');
if ($default_list) { if ($default_list) {
if (!$default_list->locked) { if (!$default_list->locked) {
$default_list->locked = TRUE; $default_list->locked = TRUE;
...@@ -21,7 +24,7 @@ function name_post_update_create_name_list_format() { ...@@ -21,7 +24,7 @@ function name_post_update_create_name_list_format() {
} }
} }
else { else {
$default_list = entity_create('name_list_format', [ $name_list_format_storage->create([
'id' => 'default', 'id' => 'default',
'label' => 'Default', 'label' => 'Default',
'locked' => TRUE, 'locked' => TRUE,
......
...@@ -4,13 +4,22 @@ namespace Drupal\name\Element; ...@@ -4,13 +4,22 @@ namespace Drupal\name\Element;
use Drupal\Core\Render\Element\FormElement; use Drupal\Core\Render\Element\FormElement;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\Core\Template\Attribute;
/** /**
* Provides a name render element. * Provides a name render element.
* *
* @RenderElement("name") * @RenderElement("name")
*/ */
class Name extends FormElement { class Name extends FormElement implements TrustedCallbackInterface {
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return ['preRender'];
}
/** /**
* Returns the element properties for this element. * Returns the element properties for this element.
...@@ -29,7 +38,7 @@ class Name extends FormElement { ...@@ -29,7 +38,7 @@ class Name extends FormElement {
return [ return [
'#input' => TRUE, '#input' => TRUE,
'#process' => ['name_element_expand'], '#process' => ['name_element_expand'],
'#pre_render' => ['name_element_pre_render'], '#pre_render' => [[__CLASS__, 'preRender']],
'#element_validate' => ['name_element_validate'], '#element_validate' => ['name_element_validate'],
'#theme_wrappers' => ['form_element'], '#theme_wrappers' => ['form_element'],
'#show_component_required_marker' => 0, '#show_component_required_marker' => 0,
...@@ -126,4 +135,40 @@ class Name extends FormElement { ...@@ -126,4 +135,40 @@ class Name extends FormElement {
return $value; 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;
}
} }
...@@ -38,7 +38,7 @@ class NameFormatDeleteConfirm extends EntityConfirmFormBase { ...@@ -38,7 +38,7 @@ class NameFormatDeleteConfirm extends EntityConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state); parent::submitForm($form, $form_state);
$this->entity->delete(); $this->entity->delete();
drupal_set_message($this->t('The name format %label has been deleted.', ['%label' => $this->entity->label()])); $this->messenger()->addMessage($this->t('The name format %label has been deleted.', ['%label' => $this->entity->label()]));
$form_state->setRedirectUrl($this->getCancelUrl()); $form_state->setRedirectUrl($this->getCancelUrl());
} }
......
...@@ -108,10 +108,10 @@ class NameFormatForm extends EntityForm { ...@@ -108,10 +108,10 @@ class NameFormatForm extends EntityForm {
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
$form_state->setRedirect('name.name_format_list'); $form_state->setRedirect('name.name_format_list');
if ($this->entity->isNew()) { if ($this->entity->isNew()) {
drupal_set_message($this->t('Name format %label added.', ['%label' => $this->entity->label()])); $this->messenger()->addMessage($this->t('Name format %label added.', ['%label' => $this->entity->label()]));
} }
else { else {
drupal_set_message($this->t('Name format %label has been updated.', ['%label' => $this->entity->label()])); $this->messenger()->addMessage($this->t('Name format %label has been updated.', ['%label' => $this->entity->label()]));
} }
$this->entity->save(); $this->entity->save();
} }
......
...@@ -38,7 +38,7 @@ class NameListFormatDeleteConfirm extends EntityConfirmFormBase { ...@@ -38,7 +38,7 @@ class NameListFormatDeleteConfirm extends EntityConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state); parent::submitForm($form, $form_state);
$this->entity->delete(); $this->entity->delete();
drupal_set_message($this->t('The name list format %label has been deleted.', ['%label' => $this->entity->label()])); $this->messenger()->addMessage($this->t('The name list format %label has been deleted.', ['%label' => $this->entity->label()]));
$form_state->setRedirectUrl($this->getCancelUrl()); $form_state->setRedirectUrl($this->getCancelUrl());
} }
......
...@@ -122,10 +122,10 @@ class NameListFormatForm extends EntityForm { ...@@ -122,10 +122,10 @@ class NameListFormatForm extends EntityForm {
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
$form_state->setRedirect('name.name_list_format_list'); $form_state->setRedirect('name.name_list_format_list');
if ($this->entity->isNew()) { if ($this->entity->isNew()) {
drupal_set_message($this->t('Name list format %label added.', ['%label' => $this->entity->label()])); $this->messenger()->addMessage($this->t('Name list format %label added.', ['%label' => $this->entity->label()]));
} }
else { else {
drupal_set_message($this->t('Name list format %label has been updated.', ['%label' => $this->entity->label()])); $this->messenger()->addMessage($this->t('Name list format %label has been updated.', ['%label' => $this->entity->label()]));
} }
$this->entity->save(); $this->entity->save();
} }
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace Drupal\name; namespace Drupal\name;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
/** /**
...@@ -147,13 +146,13 @@ class NameAutocomplete { ...@@ -147,13 +146,13 @@ class NameAutocomplete {
// We should have nice clean parameters to query. // We should have nice clean parameters to query.
if (!empty($pieces) && !empty($action['components'])) { if (!empty($pieces) && !empty($action['components'])) {
$test_string = Unicode::strtolower(array_pop($pieces)); $test_string = mb_strtolower(array_pop($pieces));
$base_string = Unicode::substr($string, 0, Unicode::strlen($string) - Unicode::strlen($test_string)); $base_string = mb_substr($string, 0, mb_strlen($string) - mb_strlen($test_string));
if ($limit > 0 && count($action['source']['title'])) { if ($limit > 0 && count($action['source']['title'])) {
$options = $this->optionsProvider->getOptions($field, 'title'); $options = $this->optionsProvider->getOptions($field, 'title');
foreach ($options as $key => $option) { foreach ($options as $key => $option) {
if (strpos(Unicode::strtolower($key), $test_string) === 0 || strpos(Unicode::strtolower($option), $test_string) === 0) { if (strpos(mb_strtolower($key), $test_string) === 0 || strpos(mb_strtolower($option), $test_string) === 0) {
$matches[$base_string . $key] = $key; $matches[$base_string . $key] = $key;
$limit--; $limit--;
} }
...@@ -163,7 +162,7 @@ class NameAutocomplete { ...@@ -163,7 +162,7 @@ class NameAutocomplete {
if ($limit > 0 && count($action['source']['generational'])) { if ($limit > 0 && count($action['source']['generational'])) {
$options = $this->optionsProvider->getOptions($field, 'generational'); $options = $this->optionsProvider->getOptions($field, 'generational');
foreach ($options as $key => $option) { foreach ($options as $key => $option) {
if (strpos(Unicode::strtolower($key), $test_string) === 0 || strpos(Unicode::strtolower($option), $test_string) === 0) { if (strpos(mb_strtolower($key), $test_string) === 0 || strpos(mb_strtolower($option), $test_string) === 0) {
$matches[$base_string . $key] = $key; $matches[$base_string . $key] = $key;
$limit--; $limit--;
} }
......
...@@ -42,7 +42,7 @@ class NameFormatListBuilder extends ConfigEntityListBuilder { ...@@ -42,7 +42,7 @@ class NameFormatListBuilder extends ConfigEntityListBuilder {
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static( return new static(
$entity_type, $entity_type,
$container->get('entity.manager')->getStorage($entity_type->id()), $container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('name.format_parser'), $container->get('name.format_parser'),
$container->get('name.generator') $container->get('name.generator')
); );
......
...@@ -68,7 +68,7 @@ class NameFormatParser { ...@@ -68,7 +68,7 @@ class NameFormatParser {
* @return \Drupal\Component\Render\MarkupInterface * @return \Drupal\Component\Render\MarkupInterface
* A renderable object representing the name. * A renderable object representing the name.
*/ */
public function parse($name_components, $format = '', array $settings = []) { public function parse(array $name_components, $format = '', array $settings = []) {
foreach (['sep1', 'sep2', 'sep3'] as $sep_key) { foreach (['sep1', 'sep2', 'sep3'] as $sep_key) {
if (isset($settings[$sep_key])) { if (isset($settings[$sep_key])) {
$this->{$sep_key} = (string) $settings[$sep_key]; $this->{$sep_key} = (string) $settings[$sep_key];
...@@ -108,7 +108,7 @@ class NameFormatParser { ...@@ -108,7 +108,7 @@ class NameFormatParser {
* @return string * @return string
* The formatted string. * The formatted string.
*/ */
protected function format($name_components, $format = '', $tokens = NULL) { protected function format(array $name_components, $format = '', array $tokens = NULL) {
if (empty($format)) { if (empty($format)) {
return ''; return '';
} }
...@@ -288,11 +288,11 @@ class NameFormatParser { ...@@ -288,11 +288,11 @@ class NameFormatParser {
for ($j = 0; $j < strlen($modifiers); $j++) { for ($j = 0; $j < strlen($modifiers); $j++) {
switch ($modifiers[$j]) { switch ($modifiers[$j]) {
case 'L': case 'L':
$string = Unicode::strtolower($string); $string = mb_strtolower($string);
break; break;
case 'U': case 'U':
$string = Unicode::strtoupper($string); $string = mb_strtoupper($string);
break; break;
case 'F': case 'F':
...@@ -368,7 +368,7 @@ class NameFormatParser { ...@@ -368,7 +368,7 @@ class NameFormatParser {
* @return array * @return array
* The keyed tokens generated for the given name. * The keyed tokens generated for the given name.
*/ */
protected function generateTokens($name_components) { protected function generateTokens(array $name_components) {
$name_components = (array) $name_components; $name_components = (array) $name_components;
$name_components += [ $name_components += [
'title' => '', 'title' => '',
...@@ -474,13 +474,13 @@ class NameFormatParser { ...@@ -474,13 +474,13 @@ class NameFormatParser {
* The rendered componenet. * The rendered componenet.
*/ */
protected function renderComponent($value, $component_key, $modifier = NULL) { protected function renderComponent($value, $component_key, $modifier = NULL) {
if (empty($value) || !Unicode::strlen($value)) { if (empty($value) || !mb_strlen($value)) {
return NULL; return NULL;
} }
switch ($modifier) { switch ($modifier) {
// First letter first word. // First letter first word.
case 'initial': case 'initial':
$value = Unicode::substr($value, 0, 1); $value = mb_substr($value, 0, 1);
break; break;
// First letter all words. // First letter all words.
...@@ -602,13 +602,13 @@ class NameFormatParser { ...@@ -602,13 +602,13 @@ class NameFormatParser {
if (preg_match('/^[a-z]+$/', $letter)) { if (preg_match('/^[a-z]+$/', $letter)) {
$tokens[$letter] = $this->t('@description<br><small>(lowercase @letter)</small>', [ $tokens[$letter] = $this->t('@description<br><small>(lowercase @letter)</small>', [
'@description' => $description, '@description' => $description,
'@letter' => Unicode::strtoupper($letter), '@letter' => mb_strtoupper($letter),
]); ]);
} }
elseif (preg_match('/^[A-Z]+$/', $letter)) { elseif (preg_match('/^[A-Z]+$/', $letter)) {
$tokens[$letter] = $this->t('@description<br><small>(uppercase @letter)</small>', [ $tokens[$letter] = $this->t('@description<br><small>(uppercase @letter)</small>', [
'@description' => $description, '@description' => $description,
'@letter' => Unicode::strtoupper($letter), '@letter' => mb_strtoupper($letter),
]); ]);
} }
} }
......
...@@ -42,7 +42,7 @@ class NameListFormatListBuilder extends ConfigEntityListBuilder { ...@@ -42,7 +42,7 @@ class NameListFormatListBuilder extends ConfigEntityListBuilder {
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static( return new static(
$entity_type, $entity_type,
$container->get('entity.manager')->getStorage($entity_type->id()), $container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('name.formatter'), $container->get('name.formatter'),
$container->get('name.format_parser'), $container->get('name.format_parser'),
$container->get('name.generator') $container->get('name.generator')
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace Drupal\name; namespace Drupal\name;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
...@@ -48,15 +47,15 @@ class NameOptionsProvider { ...@@ -48,15 +47,15 @@ class NameOptionsProvider {
protected $vocabularyStorage; protected $vocabularyStorage;
/** /**
* Contructs the service. * Constructs a new NameOptionsProvider object.
* *
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager. * The entity type manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler. * The module handler.
*/ */
public function __construct(EntityTypeManagerInterface $entityTypeManager, ModuleHandlerInterface $module_handler) { public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler) {
$this->entityTypeManager = $entityTypeManager; $this->entityTypeManager = $entity_type_manager;
$this->moduleHandler = $module_handler; $this->moduleHandler = $module_handler;
if ($this->entityTypeManager && $this->moduleHandler->moduleExists('taxonomy')) { if ($this->entityTypeManager && $this->moduleHandler->moduleExists('taxonomy')) {
...@@ -79,7 +78,7 @@ class NameOptionsProvider { ...@@ -79,7 +78,7 @@ class NameOptionsProvider {
if ($vocabulary) { if ($vocabulary) {
$max_length = isset($fs['max_length'][$component]) ? $fs['max_length'][$component] : 255; $max_length = isset($fs['max_length'][$component]) ? $fs['max_length'][$component] : 255;
foreach ($this->termStorage->loadTree($vocabulary->id()) as $term) { foreach ($this->termStorage->loadTree($vocabulary->id()) as $term) {
if (Unicode::strlen($term->name) <= $max_length) { if (mb_strlen($term->name) <= $max_length) {
$options[] = $term->name; $options[] = $term->name;