Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
65 / 65
100.00% covered (success)
100.00%
4 / 4
CRAP
n/a
0 / 0
name_update_last_removed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
name_update_8202
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
name_update_8203
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
1 / 1
3
name_update_8204
100.00% covered (success)
100.00%
33 / 33
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3/**
4 * @file
5 * Standard installation functions for name.
6 */
7
8use Symfony\Component\Yaml\Yaml;
9
10/**
11 * Implements hook_update_last_removed().
12 */
13function name_update_last_removed(): int {
14  return 8001;
15}
16
17/**
18 * Register the new name list format plugin.
19 */
20function name_update_8202() {
21  // Create the entity type.
22  \Drupal::entityTypeManager()->clearCachedDefinitions();
23  $name_list_format = \Drupal::entityTypeManager()->getDefinition('name_list_format');
24  \Drupal::entityDefinitionUpdateManager()->installEntityType($name_list_format);
25}
26
27/**
28 * Loads the name generator services files into the active configuration.
29 */
30function name_update_8203() {
31  $config_factory = \Drupal::configFactory();
32
33  $config_path = \Drupal::service('extension.list.module')->getPath('name') . '/config/install/name.generate.components.yml';
34  $data = Yaml::parse(file_get_contents($config_path));
35  $config = $config_factory->getEditable('name.generate.components');
36  $config->set('components', $data['components']);
37  $config->set('gender', $data['gender']);
38  $config->save(TRUE);
39
40  $config_path = \Drupal::service('extension.list.module')->getPath('name') . '/config/install/name.generate.preferred.yml';
41  $data = Yaml::parse(file_get_contents($config_path));
42  $config = $config_factory->getEditable('name.generate.preferred');
43  $config->set('preferred', $data['preferred']);
44  $config->save(TRUE);
45
46  if ($examples = $config_factory->get('name.examples.default')->get('examples')) {
47    $config = $config_factory->getEditable('name.generate.examples');
48    if (!empty($examples[0]['title'])) {
49      $examples[0] += [
50        'preferred' => 'Joe',
51        'alternative' => 'Lorem ipsum dolor',
52      ];
53    }
54    $config->set('examples', $examples);
55    $config->save(TRUE);
56    $old_config = $config_factory->getEditable('name.examples.default');
57    $old_config->delete();
58  }
59  else {
60    $config_path = \Drupal::service('extension.list.module')->getPath('name') . '/config/install/name.generate.examples.yml';
61    $data = Yaml::parse(file_get_contents($config_path));
62    $config = $config_factory->getEditable('name.generate.examples');
63    $config->set('examples', $data['examples']);
64    $config->save(TRUE);
65  }
66}
67
68/**
69 * Loads the name generator services files into the active configuration.
70 */
71function name_update_8204() {
72  $name_generate_components = <<<YAML
73components:
74  title:
75    - Dr.
76    - Prof.
77  given: []
78  middle: []
79  family:
80    - Adams
81    - Alexander
82    - Allen
83    - Anderson
84    - Bailey
85    - Baker
86    - Barness
87    - Bell
88    - Bennett
89    - Brooks
90    - Brown
91    - Bryant
92    - Butler
93    - Campbell
94    - Carter
95    - Clark
96    - Coleman
97    - Collins
98    - Cook
99    - Cooper
100    - Cox
101    - Davis
102    - Diaz
103    - Edwards
104    - Evans
105    - Flores
106    - Foster
107    - Garcia
108    - Gonzales
109    - Gonzales
110    - Gray
111    - Green
112    - Griffin
113    - Hall
114    - Harris
115    - Hayes
116    - Henderson
117    - Hernandez
118    - Hill
119    - Howard
120    - Hughes
121    - Jackson
122    - James
123    - Jenkins
124    - Johnson
125    - Kelly
126    - King
127    - Lee
128    - Lewis
129    - Long
130    - Lopez
131    - Martin
132    - Martinez
133    - Miller
134    - Mitchell
135    - Moore
136    - Morgan
137    - Morris
138    - Murphy
139    - Nelson
140    - Parker
141    - Patterson
142    - Perez
143    - Perry
144    - Peterson
145    - Phillips
146    - Powel
147    - Price
148    - Ramirez
149    - Reed
150    - Richardson
151    - Rivera
152    - Roberts
153    - Robinson
154    - Rodrigez
155    - Rogers
156    - Ross
157    - Russel
158    - Sanches
159    - Sanders
160    - Scott
161    - Simpson
162    - Smith
163    - Stewart
164    - Taylor
165    - Thomas
166    - Tompson
167    - Torez
168    - Turner
169    - Walker
170    - Ward
171    - Washington
172    - Watson
173    - White
174    - Williams
175    - Wilson
176    - Wood
177    - Wright
178    - Young
179  generational:
180    - Jr.
181    - Sr.
182    - I
183    - II
184    - III
185    - IV
186    - V
187    - VI
188    - VII
189    - VIII
190    - IX
191    - X
192  credentials:
193    - DPhil
194    - PhD
195    - DLitt
196    - MD
197    - EdD
198    - MA
199    - MSc
200    - MPhil
201    - MRes
202    - BA
203    - BSc
204    - BAppSc
205    - PgDip
206    - Cert
207    - JP
208gender:
209  female:
210    title:
211      - Mrs.
212      - Miss
213      - Ms.
214    given:
215      - Alexandra
216      - Allison
217      - Angela
218      - Anne
219      - Ann
220      - Amanda
221      - Barbara
222      - Caitlin
223      - Carolyn
224      - Catherine
225      - Christina
226      - Christine
227      - Danielle
228      - Deborah
229      - Debra
230      - Dorothy
231      - Ellen
232      - Elizabeth
233      - Eleanor
234      - Fiona
235      - Francesca
236      - Gabriela
237      - Gracia
238      - Helen
239      - Isabella
240      - Jacklyn
241      - Janet
242      - Jasmin
243      - Jennifer
244      - Jillian
245      - Jessica
246      - Joanna
247      - Judith
248      - Julia
249      - Kaitlin
250      - Katherine
251      - Katrina
252      - Kimberley
253      - Kristen
254      - Laura
255      - Lillian
256      - Linda
257      - Louise
258      - Lucille
259      - Margaret
260      - Mary
261      - Megan
262      - Melanie
263      - Michelle
264      - Nancy
265      - Natasha
266      - Nicole
267      - Olive
268      - Pamela
269      - Patricia
270      - Paula
271      - Philippa
272      - Priscilla
273      - Rachel
274      - Rebecca
275      - Rosemary
276      - Samantha
277      - Sarah
278      - Sharon
279      - Stephanie
280      - Susan
281      - Valerie
282      - Veronica
283      - Victoria
284      - Virginia
285      - Wendy
286      - Zoe
287    middle:
288      - Alexandra
289      - Allison
290      - Angela
291      - Anne
292      - Ann
293      - Amanda
294      - Barbara
295      - Caitlin
296      - Carolyn
297      - Catherine
298      - Christina
299      - Christine
300      - Danielle
301      - Deborah
302      - Debra
303      - Dorothy
304      - Ellen
305      - Elizabeth
306      - Eleanor
307      - Fiona
308      - Francesca
309      - Gabriela
310      - Gracia
311      - Helen
312      - Isabella
313      - Jacklyn
314      - Janet
315      - Jasmin
316      - Jennifer
317      - Jillian
318      - Jessica
319      - Joanna
320      - Judith
321      - Julia
322      - Kaitlin
323      - Katherine
324      - Katrina
325      - Kimberley
326      - Kristen
327      - Laura
328      - Lillian
329      - Linda
330      - Louise
331      - Lucille
332      - Margaret
333      - Mary
334      - Megan
335      - Melanie
336      - Michelle
337      - Nancy
338      - Natasha
339      - Nicole
340      - Olive
341      - Pamela
342      - Patricia
343      - Paula
344      - Philippa
345      - Priscilla
346      - Rachel
347      - Rebecca
348      - Rosemary
349      - Samantha
350      - Sarah
351      - Sharon
352      - Stephanie
353      - Susan
354      - Valerie
355      - Veronica
356      - Victoria
357      - Virginia
358      - Wendy
359      - Zoe
360    family: []
361    generational: []
362    credentials: []
363  male:
364    title:
365      - Mr.
366    given:
367      - Abraham
368      - Alan
369      - Alastair
370      - Albert
371      - Alfred
372      - Andrew
373      - Anthony
374      - Arthur
375      - Barnaby
376      - Benjamin
377      - Bennett
378      - Bradley
379      - Calvin
380      - Charles
381      - Christopher
382      - Clayton
383      - Christian
384      - Daniel
385      - David
386      - Dennis
387      - Dominic
388      - Donald
389      - Edward
390      - Edwin
391      - Frances
392      - Franklin
393      - Frederick
394      - Gabriel
395      - Gerald
396      - Gregory
397      - Harry
398      - Henry
399      - Herbert
400      - Howard
401      - Jackson
402      - Jacob
403      - James
404      - Jeffrey
405      - John
406      - Jonathan
407      - Joseph
408      - Kenneth
409      - Lawrence
410      - Lewis
411      - Louis
412      - Martin
413      - Matthew
414      - Michael
415      - Nathan
416      - Nathaniel
417      - Nicholas
418      - Oscar
419      - Oliver
420      - Patrick
421      - Peter
422      - Phillip
423      - Quintin
424      - Raphael
425      - Raymond
426      - Richard
427      - Robert
428      - Ronald
429      - Simon
430      - Samuel
431      - Stephen
432      - Steven
433      - Stewart
434      - Theodore
435      - Thomas
436      - Timothy
437      - Victor
438      - Vincent
439      - Walter
440      - William
441      - Zachary
442      - Zane
443    middle:
444      - Abraham
445      - Alan
446      - Alastair
447      - Albert
448      - Alfred
449      - Andrew
450      - Anthony
451      - Arthur
452      - Barnaby
453      - Benjamin
454      - Bennett
455      - Bradley
456      - Calvin
457      - Charles
458      - Christopher
459      - Clayton
460      - Christian
461      - Daniel
462      - David
463      - Dennis
464      - Dominic
465      - Donald
466      - Edward
467      - Edwin
468      - Frances
469      - Franklin
470      - Frederick
471      - Gabriel
472      - Gerald
473      - Gregory
474      - Harry
475      - Henry
476      - Herbert
477      - Howard
478      - Jackson
479      - Jacob
480      - James
481      - Jeffrey
482      - John
483      - Jonathan
484      - Joseph
485      - Kenneth
486      - Lawrence
487      - Lewis
488      - Louis
489      - Martin
490      - Matthew
491      - Michael
492      - Nathan
493      - Nathaniel
494      - Nicholas
495      - Oscar
496      - Oliver
497      - Patrick
498      - Peter
499      - Phillip
500      - Quintin
501      - Raphael
502      - Raymond
503      - Richard
504      - Robert
505      - Ronald
506      - Simon
507      - Samuel
508      - Stephen
509      - Steven
510      - Stewart
511      - Theodore
512      - Thomas
513      - Timothy
514      - Victor
515      - Vincent
516      - Walter
517      - William
518      - Zachary
519      - Zane
520    family: []
521    generational: []
522    credentials: []
523YAML;
524
525  $name_generate_preferred = <<<YAML
526preferred:
527  Abraham: Abe
528  Alan: Al
529  Alastair: Alex
530  Albert: Bert
531  Alexandra: Sandy
532  Alfred: Fred
533  Allison: Ali
534  Amanda: Mandy
535  Andrew: Drew
536  Angela: Ang
537  Anne: Nancy
538  Nancy: Anne
539  Anthony: Tony
540  Arthur: Art
541  Barbara: Bobbie
542  Barnaby: Barney
543  Benjamin: Jamie
544  Bennett: Ben
545  Bradley: Brad
546  Caitlin: Cate
547  Calvin: Cal
548  Carolyn: Lyn
549  Catherine: Cathy
550  Charles: Chuck
551  Christina: Tina
552  Christine: Chris
553  Christopher: Kit
554  Clayton: Clay
555  Christian: Chris
556  Daniel: Danny
557  Danielle: Dani
558  David: Davy
559  Deborah: Deb
560  Debra: Deb
561  Dennis: Denny
562  Dominic: Nick
563  Donald: Don
564  Dorothy: Dot
565  Edward: Ned
566  Edwin: Eddie
567  Eleanor: Nora
568  Elizabeth: Liz
569  Ellen: Nell
570  Fiona: Fi
571  Frances: Frankie
572  Franklin: Frank
573  Frederick: Fred
574  Gabriel: Gabe
575  Gerald: Jerry
576  Gregory: Greg
577  Harry: Haz
578  Helen: Nell
579  Henry: Hank
580  Herbert: Bert
581  Howard: Howie
582  Isabella: Isa
583  Jackson: Jack
584  Jacob: Jay
585  James: Jimbo
586  Janet: Jan
587  Jeffrey: Jeff
588  Jennifer: Jen
589  Jessica: Jess
590  Jillian: Jill
591  Joanna: Jo
592  John: Jack
593  Jonathan: Nathan
594  Joseph: Joey
595  Katherine: Kitty
596  Katrina: Kat
597  Kenneth: Ken
598  Kimberley: Kim
599  Kristen: Krissy
600  Laura: Lori
601  Lawrence: Larry
602  Lewis: Lewie
603  Lillian: Lilly
604  Louis: Lou
605  Louise: Lou
606  Lucille: Lucy
607  Margaret: Peg
608  Martin: Marty
609  Mary: Daisie
610  Matthew: Matt
611  Megan: Meg
612  Michael: Mikey
613  Michelle: Shelly
614  Nathan: Nate
615  Nathaniel: Nat
616  Nicholas: Nick
617  Nicole: Nicky
618  Olive: Liv
619  Oliver: Olly
620  Oscar: Ozzy
621  Pamela: Pam
622  Patricia: Trish
623  Patrick: Pat
624  Peter: Pete
625  Philippa: Pip
626  Phillip: Phil
627  Priscilla: Cilla
628  Jacklyn: Jack
629  Julia: Lea
630  Kaitlin: Kat
631  Quintin: Quinn
632  Ann: Nancy
633  Linda: Lynn
634  Raphael: Ralph
635  Francesca: Fran
636  Gabriela: Gabby
637  Gracia: Grace
638  Jasmin: Jazz
639  Judith: Judy
640  Raymond: Ray
641  Rebecca: Bec
642  Richard: Dick
643  Robert: Bobby
644  Ronald: Ronnie
645  Rosemary: Rose
646  Samantha: Sam
647  Samuel: Sammy
648  Sarah: Sally
649  Sharon: Shaza
650  Simon: Sam
651  Stephanie: Steph
652  Stephen: Steve
653  Steven: Steve
654  Stewart: Stewie
655  Susan: Sue
656  Theodore: Ted
657  Thomas: Tom
658  Timothy: Tim
659  Valerie: Val
660  Veronica: Ronnie
661  Victor: Vic
662  Victoria: Tori
663  Vincent: Vince
664  Virginia: Ginny
665  Walter: Walt
666  William: Bill
667  Zachary: Zack
668  Zane: Bo
669  Zoe: Zoey
670  Melanie: Mel
671  Natasha: Tasha
672  Paula: Polly
673  Rachel: Ray
674  Wendy: Peggy
675YAML;
676
677  $name_generate_examples = <<<YAML
678examples:
679  -
680    title: 'Mr'
681    given: 'John'
682    middle: 'Peter Mark'
683    family: 'Doe'
684    generational: 'Jnr.'
685    credentials: 'B.Sc., Ph.D.'
686    preferred: 'Joe'
687    alternative: 'Lorem ipsum dolor'
688  -
689    title: ''
690    given: 'JOAN'
691    middle: 'SUE'
692    family: 'SMITH'
693    generational: ''
694    credentials: ''
695  -
696    title: ''
697    given: 'Prince'
698    middle: ''
699    family: ''
700    generational: ''
701    credentials: ''
702
703YAML;
704
705  $config_factory = \Drupal::configFactory();
706  $name_generate_components_data = Yaml::parse($name_generate_components);
707  $components_config = $config_factory->getEditable('name.generate.components');
708  $components_config->set('components', $name_generate_components_data['components']);
709  $components_config->set('gender', $name_generate_components_data['gender']);
710  $components_config->save(TRUE);
711
712  $name_generate_preferred_data = Yaml::parse($name_generate_preferred);
713  $preferred_config = $config_factory->getEditable('name.generate.preferred');
714  if ($preferred_config->isNew()) {
715    $preferred_config->set('preferred', $name_generate_preferred_data['preferred']);
716    $preferred_config->save(TRUE);
717  }
718
719  if ($examples = $config_factory->get('name.examples.default')->get('examples')) {
720    $examples_config = $config_factory->getEditable('name.generate.examples');
721    if (!empty($examples[0]['title'])) {
722      $examples[0] += [
723        'preferred' => 'Joe',
724        'alternative' => 'Lorem ipsum dolor',
725      ];
726    }
727    $examples_config->set('examples', $examples);
728    $examples_config->save(TRUE);
729    $old_config = $config_factory->getEditable('name.examples.default');
730    $old_config->delete();
731  }
732  elseif ($config_factory->get('name.generate.examples')->isNew()) {
733    $name_generate_examples_data = Yaml::parse($name_generate_examples);
734    $examples_config = $config_factory->getEditable('name.generate.examples');
735    $examples_config->set('examples', $name_generate_examples_data['examples']);
736    $examples_config->save(TRUE);
737  }
738}