diff --git a/name.install b/name.install index 1187c26..5733b45 100644 --- a/name.install +++ b/name.install @@ -18,7 +18,7 @@ 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"); + $result = \Drupal::database()->query("SELECT * FROM {name_custom_format} ORDER BY name ASC"); foreach ($result as $row) { \Drupal::config('name_format.' . $row->machine_name) @@ -58,7 +58,7 @@ function name_update_8001() { variable_del('name_element_wrapper'); variable_del('name_component_required_marker'); - db_drop_table('name_custom_format'); + \Drupal::database()->schema()->dropTable('name_custom_format'); } /** diff --git a/name.module b/name.module index e9eb86f..37e16fb 100644 --- a/name.module +++ b/name.module @@ -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; } } diff --git a/name.post_update.php b/name.post_update.php index c6dd9f8..1c2110d 100644 --- a/name.post_update.php +++ b/name.post_update.php @@ -4,7 +4,7 @@ * @file * Post update functions for Name. */ - +use Drupal\node\Entity\Node; /** * Adds the default list format. */ @@ -21,7 +21,7 @@ function name_post_update_create_name_list_format() { } } else { - $default_list = entity_create('name_list_format', [ + $default_list = Node::create('name_list_format', [ 'id' => 'default', 'label' => 'Default', 'locked' => TRUE, diff --git a/src/Form/NameFormatDeleteConfirm.php b/src/Form/NameFormatDeleteConfirm.php index 5977543..7c3525f 100644 --- a/src/Form/NameFormatDeleteConfirm.php +++ b/src/Form/NameFormatDeleteConfirm.php @@ -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()); } diff --git a/src/Form/NameFormatForm.php b/src/Form/NameFormatForm.php index d253ab9..459bcc3 100644 --- a/src/Form/NameFormatForm.php +++ b/src/Form/NameFormatForm.php @@ -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(); } diff --git a/src/Form/NameListFormatDeleteConfirm.php b/src/Form/NameListFormatDeleteConfirm.php index ca0d251..afe880c 100644 --- a/src/Form/NameListFormatDeleteConfirm.php +++ b/src/Form/NameListFormatDeleteConfirm.php @@ -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()); } diff --git a/src/Form/NameListFormatForm.php b/src/Form/NameListFormatForm.php index 5e18670..9829064 100644 --- a/src/Form/NameListFormatForm.php +++ b/src/Form/NameListFormatForm.php @@ -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(); } diff --git a/src/NameAutocomplete.php b/src/NameAutocomplete.php index 7c917d3..aabea7b 100644 --- a/src/NameAutocomplete.php +++ b/src/NameAutocomplete.php @@ -117,8 +117,8 @@ class NameAutocomplete { $sep = ' '; } for ($i = 0; $i < strlen($sep); $i++) { - if (strpos($action['separater'], $sep{$i}) === FALSE) { - $action['separater'] .= $sep{$i}; + if (strpos($action['separater'], $sep[$i]) === FALSE) { + $action['separater'] .= $sep[$i]; } } $found_source = FALSE; @@ -147,13 +147,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 +163,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--; } diff --git a/src/NameFormatParser.php b/src/NameFormatParser.php index c0236ff..73f35bd 100644 --- a/src/NameFormatParser.php +++ b/src/NameFormatParser.php @@ -124,8 +124,8 @@ class NameFormatParser { $modifiers = ''; $conditions = ''; for ($i = 0; $i < strlen($format); $i++) { - $char = $format{$i}; - $last_char = ($i > 0) ? $format{$i - 1} : FALSE; + $char = $format[$i]; + $last_char = ($i > 0) ? $format[$i - 1] : FALSE; // Handle escaped letters. if ($char == '\\') { @@ -286,13 +286,13 @@ class NameFormatParser { } for ($j = 0; $j < strlen($modifiers); $j++) { - switch ($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': @@ -345,7 +345,7 @@ class NameFormatParser { $depth = 0; $string = str_replace(['\(', '\)'], ['__', '__'], $string); for ($i = 0; $i < strlen($string); $i++) { - $char = $string{$i}; + $char = $string[$i]; if ($char == '(') { $depth++; } @@ -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
(lowercase @letter)', [ '@description' => $description, - '@letter' => Unicode::strtoupper($letter), + '@letter' => mb_strtoupper($letter), ]); } elseif (preg_match('/^[A-Z]+$/', $letter)) { $tokens[$letter] = $this->t('@description
(uppercase @letter)', [ '@description' => $description, - '@letter' => Unicode::strtoupper($letter), + '@letter' => mb_strtoupper($letter), ]); } } diff --git a/src/NameOptionsProvider.php b/src/NameOptionsProvider.php index 5988785..1c13cd8 100644 --- a/src/NameOptionsProvider.php +++ b/src/NameOptionsProvider.php @@ -79,7 +79,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 +98,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); diff --git a/src/NameUnicodeExtras.php b/src/NameUnicodeExtras.php index 634a640..f0e91f9 100644 --- a/src/NameUnicodeExtras.php +++ b/src/NameUnicodeExtras.php @@ -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 : ''; } diff --git a/src/Plugin/migrate/cckfield/NameItem.php b/src/Plugin/migrate/cckfield/NameItem.php index 9d812e0..375efcf 100644 --- a/src/Plugin/migrate/cckfield/NameItem.php +++ b/src/Plugin/migrate/cckfield/NameItem.php @@ -3,8 +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 +14,7 @@ use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase; * destination_module = "name", * ) */ -class NameItem extends CckFieldPluginBase { +class NameItem extends FieldPluginBase { /** * {@inheritdoc} diff --git a/src/Plugin/views/filter/Fulltext.php b/src/Plugin/views/filter/Fulltext.php index 1827736..d5c6aab 100644 --- a/src/Plugin/views/filter/Fulltext.php +++ b/src/Plugin/views/filter/Fulltext.php @@ -5,6 +5,7 @@ namespace Drupal\name\Plugin\views\filter; use Drupal\Component\Utility\Unicode; use Drupal\Core\Form\FormStateInterface; use Drupal\views\Plugin\views\filter\FilterPluginBase; +use Drupal\Core\Database\Query\Condition; /** * Filter by fulltext search. @@ -95,7 +96,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 +109,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 => '% ' . \Drupal::database()->escapeLike($word) . '%']); } $this->query->addWhere($this->options['group'], $where); diff --git a/src/Tests/NameAutocompleteTest.php b/src/Tests/NameAutocompleteTest.php index f1abffc..0a64f5b 100644 --- a/src/Tests/NameAutocompleteTest.php +++ b/src/Tests/NameAutocompleteTest.php @@ -101,7 +101,7 @@ class NameAutocompleteTest extends KernelTestBase { ]; foreach ($names as $name) { $name = explode(' ', $name); - $entity = entity_create('entity_test', [ + $entity = \Drupal::entityTypeManager()->getStorage('entity_test')->create([ 'bundle' => 'entity_test', 'field_name_test' => [ 'given' => $name[0], diff --git a/src/Tests/NameFieldTest.php b/src/Tests/NameFieldTest.php index e92b5fa..379e701 100644 --- a/src/Tests/NameFieldTest.php +++ b/src/Tests/NameFieldTest.php @@ -42,7 +42,7 @@ class NameFieldTest extends NameTestBase { parent::setUp(); // Create content-type: page. - $page = entity_create('node_type', ['type' => 'page', 'name' => 'Basic page']); + $page = \Drupal::entityTypeManager()->getStorage('node_type')->create(['type' => 'page', 'name' => 'Basic page']); $page->save(); } diff --git a/src/Tests/NameNodeTokenReplaceTest.php b/src/Tests/NameNodeTokenReplaceTest.php index f270b70..ea4679f 100644 --- a/src/Tests/NameNodeTokenReplaceTest.php +++ b/src/Tests/NameNodeTokenReplaceTest.php @@ -5,6 +5,7 @@ namespace Drupal\name\Tests; use Drupal\Core\Render\BubbleableMetadata; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; +use Drupal\Component\Render\FormattableMarkup; /** * Tests text replacements in content to check node name token replacement. @@ -116,8 +117,8 @@ class NameNodeTokenReplaceTest extends NameTestBase { $item = $account->get('field_realname')->get(0); $components = $item->filteredArray(); - $tests['[node:author:name]'] = $account->getUsername(); - $tests['[node:author:account-name]'] = $account->getUsername(); + $tests['[node:author:name]'] = $account->getAccountName(); + $tests['[node:author:account-name]'] = $account->getAccountName(); $tests['[node:author:display-name]'] = $account->getDisplayName(); $tests['[node:author:field_realname]'] = $this->formatter->format($components); $tests['[node:author:field_realname:family]'] = $components['family']; @@ -130,7 +131,7 @@ class NameNodeTokenReplaceTest extends NameTestBase { foreach ($tests as $input => $expected) { $bubbleable_metadata = new BubbleableMetadata(); $output = $this->tokenService->replace($input, ['node' => $node], ['langcode' => $this->interfaceLanguage->getId()], $bubbleable_metadata); - $this->assertEqual($output, (string) $expected, format_string('Node token %token replaced with %expected, got %actual.', [ + $this->assertEqual($output, (string) $expected, new FormattableMarkup('Node token %token replaced with %expected, got %actual.', [ '%token' => $input, '%expected' => $expected, '%actual' => $output, diff --git a/src/Tests/NameTestBase.php b/src/Tests/NameTestBase.php index 491ac1f..15a9fa4 100644 --- a/src/Tests/NameTestBase.php +++ b/src/Tests/NameTestBase.php @@ -2,12 +2,11 @@ namespace Drupal\name\Tests; -use Drupal\simpletest\WebTestBase; - +use \Drupal\Tests\BrowserTestBase; /** * Helper test class with some added functions for testing. */ -abstract class NameTestBase extends WebTestBase { +abstract class NameTestBase extends BrowserTestBase { /** * Modules to enable. diff --git a/src/Tests/NameUserTest.php b/src/Tests/NameUserTest.php index a35af4f..eda25c5 100644 --- a/src/Tests/NameUserTest.php +++ b/src/Tests/NameUserTest.php @@ -111,8 +111,8 @@ class NameUserTest extends KernelTestBase { $account = User::load($account->id()); $this->assertEqual('Max Mustermann', $account->realname); - $this->assertEqual('Max Mustermann', user_format_name($account)); - $this->assertEqual('test', $account->getUsername()); + $this->assertEqual('Max Mustermann', $account->getDisplayName()); + $this->assertEqual('test', $account->getAccountName()); $this->assertEqual('Max Mustermann', $account->getDisplayName()); } diff --git a/src/Tests/NameWidgetTest.php b/src/Tests/NameWidgetTest.php index dcdfa1a..645c369 100644 --- a/src/Tests/NameWidgetTest.php +++ b/src/Tests/NameWidgetTest.php @@ -43,7 +43,7 @@ class NameWidgetTest extends NameTestBase { parent::setUp(); // Create content-type: page. - $page = entity_create('node_type', ['type' => 'page', 'name' => 'Basic page']); + $page = \Drupal::entityTypeManager()->getStorage('node_type')->create(['type' => 'page', 'name' => 'Basic page']); $page->save(); } diff --git a/src/Traits/NameFieldSettingsTrait.php b/src/Traits/NameFieldSettingsTrait.php index acef693..a1ba00f 100644 --- a/src/Traits/NameFieldSettingsTrait.php +++ b/src/Traits/NameFieldSettingsTrait.php @@ -310,7 +310,7 @@ trait NameFieldSettingsTrait { '#items' => $items, ]; $layout_description = $this->t('

This controls the order of the widgets that are displayed in the form.

') - . drupal_render($item_list) + . \Drupal::service('renderer')->render($item_list) . $this->t('

Note that when you select the Asian and German name formats, the Generational field is hidden and defaults to an empty string.

'); $element['component_layout'] = [ '#type' => 'radios', diff --git a/src/Traits/NameFormSettingsHelperTrait.php b/src/Traits/NameFormSettingsHelperTrait.php index de96da5..6f159ff 100644 --- a/src/Traits/NameFormSettingsHelperTrait.php +++ b/src/Traits/NameFormSettingsHelperTrait.php @@ -220,7 +220,7 @@ trait NameFormSettingsHelperTrait { } } } - elseif (Unicode::strlen($value) > $max_length) { + elseif (mb_strlen($value) > $max_length) { $long_options[] = $value; } elseif (!empty($value)) {