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() {
* Upgrade from Drupal 7 to Drupal 8.
*/
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) {
\Drupal::config('name_format.' . $row->machine_name)
......@@ -57,8 +59,7 @@ function name_update_8001() {
variable_del('name_inline_styles_rtl');
variable_del('name_element_wrapper');
variable_del('name_component_required_marker');
db_drop_table('name_custom_format');
$database->schema()->dropTable('name_custom_format');
}
/**
......
......@@ -16,13 +16,13 @@ use Drupal\user\UserInterface;
use Drupal\user\Entity\User;
use Drupal\field\Entity\FieldConfig;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\name\Element\Name;
/**
* Helper function to get any defined name widget layout options.
......@@ -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
// 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', []);
if (isset($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;
}
}
......@@ -225,7 +225,8 @@ function name_get_additional_component(EntityTypeManagerInterface $entityTypeMan
}
}
}
catch (\InvalidArgumentException $e) {}
catch (\InvalidArgumentException $e) {
}
}
elseif ($parent->hasField($key_value)) {
$target_items = $parent->get($key_value);
......@@ -255,7 +256,8 @@ function name_get_additional_component(EntityTypeManagerInterface $entityTypeMan
}
}
}
catch (\Exception $e) {}
catch (\Exception $e) {
}
}
break;
......@@ -532,7 +534,7 @@ function name_element_render_component(array $components, $component_key, array
* @return array
* 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'])) {
$element['#description']['#for'] = $element['#id'];
}
......@@ -599,38 +601,12 @@ function name_element_validate($element, &$form_state) {
/**
* 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) {
$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;
return Name::preRender($element);
}
/**
......
......@@ -9,7 +9,10 @@
* Adds the default 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->locked) {
$default_list->locked = TRUE;
......@@ -21,7 +24,7 @@ function name_post_update_create_name_list_format() {
}
}
else {
$default_list = entity_create('name_list_format', [
$name_list_format_storage->create([
'id' => 'default',
'label' => 'Default',
'locked' => TRUE,
......
......@@ -4,13 +4,22 @@ namespace Drupal\name\Element;
use Drupal\Core\Render\Element\FormElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\Core\Template\Attribute;
/**
* Provides a name render element.
*
* @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.
......@@ -29,7 +38,7 @@ class Name extends FormElement {
return [
'#input' => TRUE,
'#process' => ['name_element_expand'],
'#pre_render' => ['name_element_pre_render'],
'#pre_render' => [[__CLASS__, 'preRender']],
'#element_validate' => ['name_element_validate'],
'#theme_wrappers' => ['form_element'],
'#show_component_required_marker' => 0,
......@@ -126,4 +135,40 @@ class Name extends FormElement {
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 {
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$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());
}
......
......@@ -108,10 +108,10 @@ class NameFormatForm extends EntityForm {
public function save(array $form, FormStateInterface $form_state) {
$form_state->setRedirect('name.name_format_list');
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 {
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();
}
......
......@@ -38,7 +38,7 @@ class NameListFormatDeleteConfirm extends EntityConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$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());
}
......
......@@ -122,10 +122,10 @@ class NameListFormatForm extends EntityForm {
public function save(array $form, FormStateInterface $form_state) {
$form_state->setRedirect('name.name_list_format_list');
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 {
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();
}
......
......@@ -2,7 +2,6 @@
namespace Drupal\name;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
......@@ -147,13 +146,13 @@ class NameAutocomplete {
// We should have nice clean parameters to query.
if (!empty($pieces) && !empty($action['components'])) {
$test_string = Unicode::strtolower(array_pop($pieces));
$base_string = Unicode::substr($string, 0, Unicode::strlen($string) - Unicode::strlen($test_string));
$test_string = mb_strtolower(array_pop($pieces));
$base_string = mb_substr($string, 0, mb_strlen($string) - mb_strlen($test_string));
if ($limit > 0 && count($action['source']['title'])) {
$options = $this->optionsProvider->getOptions($field, 'title');
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;
$limit--;
}
......@@ -163,7 +162,7 @@ class NameAutocomplete {
if ($limit > 0 && count($action['source']['generational'])) {
$options = $this->optionsProvider->getOptions($field, 'generational');
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;
$limit--;
}
......
......@@ -42,7 +42,7 @@ class NameFormatListBuilder extends ConfigEntityListBuilder {
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$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.generator')
);
......
......@@ -68,7 +68,7 @@ class NameFormatParser {
* @return \Drupal\Component\Render\MarkupInterface
* 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) {
if (isset($settings[$sep_key])) {
$this->{$sep_key} = (string) $settings[$sep_key];
......@@ -108,7 +108,7 @@ class NameFormatParser {
* @return 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)) {
return '';
}
......@@ -288,11 +288,11 @@ class NameFormatParser {
for ($j = 0; $j < strlen($modifiers); $j++) {
switch ($modifiers[$j]) {
case 'L':
$string = Unicode::strtolower($string);
$string = mb_strtolower($string);
break;
case 'U':
$string = Unicode::strtoupper($string);
$string = mb_strtoupper($string);
break;
case 'F':
......@@ -368,7 +368,7 @@ class NameFormatParser {
* @return array
* 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 += [
'title' => '',
......@@ -474,13 +474,13 @@ class NameFormatParser {
* The rendered componenet.
*/
protected function renderComponent($value, $component_key, $modifier = NULL) {
if (empty($value) || !Unicode::strlen($value)) {
if (empty($value) || !mb_strlen($value)) {
return NULL;
}
switch ($modifier) {
// First letter first word.
case 'initial':
$value = Unicode::substr($value, 0, 1);
$value = mb_substr($value, 0, 1);
break;
// First letter all words.
......@@ -602,13 +602,13 @@ class NameFormatParser {
if (preg_match('/^[a-z]+$/', $letter)) {
$tokens[$letter] = $this->t('@description<br><small>(lowercase @letter)</small>', [
'@description' => $description,
'@letter' => Unicode::strtoupper($letter),
'@letter' => mb_strtoupper($letter),
]);
}
elseif (preg_match('/^[A-Z]+$/', $letter)) {
$tokens[$letter] = $this->t('@description<br><small>(uppercase @letter)</small>', [
'@description' => $description,
'@letter' => Unicode::strtoupper($letter),
'@letter' => mb_strtoupper($letter),
]);
}
}
......
......@@ -42,7 +42,7 @@ class NameListFormatListBuilder extends ConfigEntityListBuilder {
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$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.format_parser'),
$container->get('name.generator')
......
......@@ -2,7 +2,6 @@
namespace Drupal\name;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
......@@ -48,15 +47,15 @@ class NameOptionsProvider {
protected $vocabularyStorage;
/**
* Contructs the service.
* Constructs a new NameOptionsProvider object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, ModuleHandlerInterface $module_handler) {
$this->entityTypeManager = $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler) {
$this->entityTypeManager = $entity_type_manager;
$this->moduleHandler = $module_handler;
if ($this->entityTypeManager && $this->moduleHandler->moduleExists('taxonomy')) {
......@@ -79,7 +78,7 @@ class NameOptionsProvider {
if ($vocabulary) {
$max_length = isset($fs['max_length'][$component]) ? $fs['max_length'][$component] : 255;
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;
}
}
......@@ -98,7 +97,7 @@ class NameOptionsProvider {
foreach ($options as $index => $opt) {
if (strpos($opt, '--') === 0) {
unset($options[$index]);
$default = trim(Unicode::substr($opt, 2));
$default = trim(mb_substr($opt, 2));
}
}
$options = array_map('trim', $options);
......
......@@ -41,13 +41,13 @@ class NameUnicodeExtras extends Unicode {
* The input $text with first letters of each word capitalized.
*/
public static function initials($text, $delimitor = '') {
$text = self::strtolower($text);
$text = mb_strtolower($text);
$results = [];
foreach (array_filter(self::explode($text)) as $word) {
$results[] = Unicode::substr($word, 0, 1);
$results[] = mb_substr($word, 0, 1);
}
$text = implode($delimitor, $results);
$text = self::strtoupper($text);
$text = mb_strtoupper($text);
return $text ? $text . $delimitor : '';
}
......
......@@ -9,6 +9,7 @@ use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\name\Traits\NameFieldSettingsTrait;
use Drupal\name\Traits\NameFormDisplaySettingsTrait;
......@@ -29,7 +30,7 @@ use Drupal\name\Traits\NameAdditionalPreferredTrait;
* default_formatter = "name_default"
* )
*/
class NameItem extends FieldItemBase {
class NameItem extends FieldItemBase implements TrustedCallbackInterface {
use NameFieldSettingsTrait;
use NameFormDisplaySettingsTrait;
......@@ -50,6 +51,13 @@ class NameItem extends FieldItemBase {
'credentials',
];
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return ['fieldSettingsFormPreRender'];
}
/**
* {@inheritdoc}
*/
......
......@@ -3,7 +3,7 @@
namespace Drupal\name\Plugin\migrate\cckfield;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* Name migrate plugin.
......@@ -15,7 +15,7 @@ use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
* destination_module = "name",
* )
*/
class NameItem extends CckFieldPluginBase {
class NameItem extends FieldPluginBase {
/**
* {@inheritdoc}
......
......@@ -2,9 +2,11 @@
namespace Drupal\name\Plugin\views\filter;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Filter by fulltext search.
......@@ -15,6 +17,42 @@ use Drupal\views\Plugin\views\filter\FilterPluginBase;
*/
class Fulltext extends FilterPluginBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new Fulltext object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $connection) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('database')
);
}
/**
* Supported operations.
*/
......@@ -95,7 +133,7 @@ class Fulltext extends FilterPluginBase {
* The db field.
*/
public function op_contains($fulltext_field) {
$value = Unicode::strtolower($this->value[0]);
$value = mb_strtolower($this->value[0]);
$value = str_replace(' ', '%', $value);
$placeholder = $this->placeholder();
$this->query->addWhereExpression($this->options['group'], "$fulltext_field LIKE $placeholder", [$placeholder => '% ' . $value . '%']);
......@@ -108,13 +146,13 @@ class Fulltext extends FilterPluginBase {
* The db field.
*/
public function op_word($fulltext_field) {
$where = $this->operator == 'word' ? db_or() : db_and();
$value = Unicode::strtolower($this->value[0]);
$where = $this->operator == 'word' ? new Condition('OR') : new Condition('AND');
$value = mb_strtolower($this->value[0]);
$words = preg_split('/ /', $value, -1, PREG_SPLIT_NO_EMPTY);
foreach ($words as $word) {
$placeholder = $this->placeholder();
$where->where("$fulltext_field LIKE $placeholder", [$placeholder => '% ' . db_like($word) . '%']);
$where->where("$fulltext_field LIKE $placeholder", [$placeholder => '% ' . $this->connection->escapeLike($word) . '%']);
}
$this->query->addWhere($this->options['group'], $where);
......
<?php
namespace Drupal\name\Tests;
namespace Drupal\Tests\name\Functional;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
......@@ -19,7 +19,7 @@ class NameAdminTest extends NameTestBase {
*/
public function testAdminFormatSettings() {
// Default settings and system settings.
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
// The default installed formats.
$this->drupalGet('admin/config/regional/name');
......@@ -183,7 +183,7 @@ class NameAdminTest extends NameTestBase {
$this->drupalGet('admin/config/regional/name/manage/test/delete');
$this->assertText(t('Are you sure you want to delete the custom format @title?', ['@title' => $values['label']]));
$this->drupalPostForm(NULL, ['confirm' => 1], t('Delete'));
$this->drupalPostForm(NULL, [], t('Delete'));