name-8.x-1.x-dev/name.install

name.install
<?php

/**
 * @file
 * Standard installation functions for name.
 */

use Symfony\Component\Yaml\Yaml;

/**
 * Implements hook_update_last_removed().
 */
function name_update_last_removed(): int {
  return 8001;
}

/**
 * Register the new name list format plugin.
 */
function name_update_8202() {
  // Create the entity type.
  \Drupal::entityTypeManager()->clearCachedDefinitions();
  $name_list_format = \Drupal::entityTypeManager()->getDefinition('name_list_format');
  \Drupal::entityDefinitionUpdateManager()->installEntityType($name_list_format);
}

/**
 * Loads the name generator services files into the active configuration.
 */
function name_update_8203() {
  $config_factory = \Drupal::configFactory();

  $config_path = \Drupal::service('extension.list.module')->getPath('name') . '/config/install/name.generate.components.yml';
  $data = Yaml::parse(file_get_contents($config_path));
  $config = $config_factory->getEditable('name.generate.components');
  $config->set('components', $data['components']);
  $config->set('gender', $data['gender']);
  $config->save(TRUE);

  $config_path = \Drupal::service('extension.list.module')->getPath('name') . '/config/install/name.generate.preferred.yml';
  $data = Yaml::parse(file_get_contents($config_path));
  $config = $config_factory->getEditable('name.generate.preferred');
  $config->set('preferred', $data['preferred']);
  $config->save(TRUE);

  if ($examples = $config_factory->get('name.examples.default')->get('examples')) {
    $config = $config_factory->getEditable('name.generate.examples');
    if (!empty($examples[0]['title'])) {
      $examples[0] += [
        'preferred' => 'Joe',
        'alternative' => 'Lorem ipsum dolor',
      ];
    }
    $config->set('examples', $examples);
    $config->save(TRUE);
    $old_config = $config_factory->getEditable('name.examples.default');
    $old_config->delete();
  }
  else {
    $config_path = \Drupal::service('extension.list.module')->getPath('name') . '/config/install/name.generate.examples.yml';
    $data = Yaml::parse(file_get_contents($config_path));
    $config = $config_factory->getEditable('name.generate.examples');
    $config->set('examples', $data['examples']);
    $config->save(TRUE);
  }
}

/**
 * Loads the name generator services files into the active configuration.
 */
function name_update_8204() {
  $name_generate_components = <<<YAML
components:
  title:
    - Dr.
    - Prof.
  given: []
  middle: []
  family:
    - Adams
    - Alexander
    - Allen
    - Anderson
    - Bailey
    - Baker
    - Barness
    - Bell
    - Bennett
    - Brooks
    - Brown
    - Bryant
    - Butler
    - Campbell
    - Carter
    - Clark
    - Coleman
    - Collins
    - Cook
    - Cooper
    - Cox
    - Davis
    - Diaz
    - Edwards
    - Evans
    - Flores
    - Foster
    - Garcia
    - Gonzales
    - Gonzales
    - Gray
    - Green
    - Griffin
    - Hall
    - Harris
    - Hayes
    - Henderson
    - Hernandez
    - Hill
    - Howard
    - Hughes
    - Jackson
    - James
    - Jenkins
    - Johnson
    - Kelly
    - King
    - Lee
    - Lewis
    - Long
    - Lopez
    - Martin
    - Martinez
    - Miller
    - Mitchell
    - Moore
    - Morgan
    - Morris
    - Murphy
    - Nelson
    - Parker
    - Patterson
    - Perez
    - Perry
    - Peterson
    - Phillips
    - Powel
    - Price
    - Ramirez
    - Reed
    - Richardson
    - Rivera
    - Roberts
    - Robinson
    - Rodrigez
    - Rogers
    - Ross
    - Russel
    - Sanches
    - Sanders
    - Scott
    - Simpson
    - Smith
    - Stewart
    - Taylor
    - Thomas
    - Tompson
    - Torez
    - Turner
    - Walker
    - Ward
    - Washington
    - Watson
    - White
    - Williams
    - Wilson
    - Wood
    - Wright
    - Young
  generational:
    - Jr.
    - Sr.
    - I
    - II
    - III
    - IV
    - V
    - VI
    - VII
    - VIII
    - IX
    - X
  credentials:
    - DPhil
    - PhD
    - DLitt
    - MD
    - EdD
    - MA
    - MSc
    - MPhil
    - MRes
    - BA
    - BSc
    - BAppSc
    - PgDip
    - Cert
    - JP
gender:
  female:
    title:
      - Mrs.
      - Miss
      - Ms.
    given:
      - Alexandra
      - Allison
      - Angela
      - Anne
      - Ann
      - Amanda
      - Barbara
      - Caitlin
      - Carolyn
      - Catherine
      - Christina
      - Christine
      - Danielle
      - Deborah
      - Debra
      - Dorothy
      - Ellen
      - Elizabeth
      - Eleanor
      - Fiona
      - Francesca
      - Gabriela
      - Gracia
      - Helen
      - Isabella
      - Jacklyn
      - Janet
      - Jasmin
      - Jennifer
      - Jillian
      - Jessica
      - Joanna
      - Judith
      - Julia
      - Kaitlin
      - Katherine
      - Katrina
      - Kimberley
      - Kristen
      - Laura
      - Lillian
      - Linda
      - Louise
      - Lucille
      - Margaret
      - Mary
      - Megan
      - Melanie
      - Michelle
      - Nancy
      - Natasha
      - Nicole
      - Olive
      - Pamela
      - Patricia
      - Paula
      - Philippa
      - Priscilla
      - Rachel
      - Rebecca
      - Rosemary
      - Samantha
      - Sarah
      - Sharon
      - Stephanie
      - Susan
      - Valerie
      - Veronica
      - Victoria
      - Virginia
      - Wendy
      - Zoe
    middle:
      - Alexandra
      - Allison
      - Angela
      - Anne
      - Ann
      - Amanda
      - Barbara
      - Caitlin
      - Carolyn
      - Catherine
      - Christina
      - Christine
      - Danielle
      - Deborah
      - Debra
      - Dorothy
      - Ellen
      - Elizabeth
      - Eleanor
      - Fiona
      - Francesca
      - Gabriela
      - Gracia
      - Helen
      - Isabella
      - Jacklyn
      - Janet
      - Jasmin
      - Jennifer
      - Jillian
      - Jessica
      - Joanna
      - Judith
      - Julia
      - Kaitlin
      - Katherine
      - Katrina
      - Kimberley
      - Kristen
      - Laura
      - Lillian
      - Linda
      - Louise
      - Lucille
      - Margaret
      - Mary
      - Megan
      - Melanie
      - Michelle
      - Nancy
      - Natasha
      - Nicole
      - Olive
      - Pamela
      - Patricia
      - Paula
      - Philippa
      - Priscilla
      - Rachel
      - Rebecca
      - Rosemary
      - Samantha
      - Sarah
      - Sharon
      - Stephanie
      - Susan
      - Valerie
      - Veronica
      - Victoria
      - Virginia
      - Wendy
      - Zoe
    family: []
    generational: []
    credentials: []
  male:
    title:
      - Mr.
    given:
      - Abraham
      - Alan
      - Alastair
      - Albert
      - Alfred
      - Andrew
      - Anthony
      - Arthur
      - Barnaby
      - Benjamin
      - Bennett
      - Bradley
      - Calvin
      - Charles
      - Christopher
      - Clayton
      - Christian
      - Daniel
      - David
      - Dennis
      - Dominic
      - Donald
      - Edward
      - Edwin
      - Frances
      - Franklin
      - Frederick
      - Gabriel
      - Gerald
      - Gregory
      - Harry
      - Henry
      - Herbert
      - Howard
      - Jackson
      - Jacob
      - James
      - Jeffrey
      - John
      - Jonathan
      - Joseph
      - Kenneth
      - Lawrence
      - Lewis
      - Louis
      - Martin
      - Matthew
      - Michael
      - Nathan
      - Nathaniel
      - Nicholas
      - Oscar
      - Oliver
      - Patrick
      - Peter
      - Phillip
      - Quintin
      - Raphael
      - Raymond
      - Richard
      - Robert
      - Ronald
      - Simon
      - Samuel
      - Stephen
      - Steven
      - Stewart
      - Theodore
      - Thomas
      - Timothy
      - Victor
      - Vincent
      - Walter
      - William
      - Zachary
      - Zane
    middle:
      - Abraham
      - Alan
      - Alastair
      - Albert
      - Alfred
      - Andrew
      - Anthony
      - Arthur
      - Barnaby
      - Benjamin
      - Bennett
      - Bradley
      - Calvin
      - Charles
      - Christopher
      - Clayton
      - Christian
      - Daniel
      - David
      - Dennis
      - Dominic
      - Donald
      - Edward
      - Edwin
      - Frances
      - Franklin
      - Frederick
      - Gabriel
      - Gerald
      - Gregory
      - Harry
      - Henry
      - Herbert
      - Howard
      - Jackson
      - Jacob
      - James
      - Jeffrey
      - John
      - Jonathan
      - Joseph
      - Kenneth
      - Lawrence
      - Lewis
      - Louis
      - Martin
      - Matthew
      - Michael
      - Nathan
      - Nathaniel
      - Nicholas
      - Oscar
      - Oliver
      - Patrick
      - Peter
      - Phillip
      - Quintin
      - Raphael
      - Raymond
      - Richard
      - Robert
      - Ronald
      - Simon
      - Samuel
      - Stephen
      - Steven
      - Stewart
      - Theodore
      - Thomas
      - Timothy
      - Victor
      - Vincent
      - Walter
      - William
      - Zachary
      - Zane
    family: []
    generational: []
    credentials: []
YAML;

  $name_generate_preferred = <<<YAML
preferred:
  Abraham: Abe
  Alan: Al
  Alastair: Alex
  Albert: Bert
  Alexandra: Sandy
  Alfred: Fred
  Allison: Ali
  Amanda: Mandy
  Andrew: Drew
  Angela: Ang
  Anne: Nancy
  Nancy: Anne
  Anthony: Tony
  Arthur: Art
  Barbara: Bobbie
  Barnaby: Barney
  Benjamin: Jamie
  Bennett: Ben
  Bradley: Brad
  Caitlin: Cate
  Calvin: Cal
  Carolyn: Lyn
  Catherine: Cathy
  Charles: Chuck
  Christina: Tina
  Christine: Chris
  Christopher: Kit
  Clayton: Clay
  Christian: Chris
  Daniel: Danny
  Danielle: Dani
  David: Davy
  Deborah: Deb
  Debra: Deb
  Dennis: Denny
  Dominic: Nick
  Donald: Don
  Dorothy: Dot
  Edward: Ned
  Edwin: Eddie
  Eleanor: Nora
  Elizabeth: Liz
  Ellen: Nell
  Fiona: Fi
  Frances: Frankie
  Franklin: Frank
  Frederick: Fred
  Gabriel: Gabe
  Gerald: Jerry
  Gregory: Greg
  Harry: Haz
  Helen: Nell
  Henry: Hank
  Herbert: Bert
  Howard: Howie
  Isabella: Isa
  Jackson: Jack
  Jacob: Jay
  James: Jimbo
  Janet: Jan
  Jeffrey: Jeff
  Jennifer: Jen
  Jessica: Jess
  Jillian: Jill
  Joanna: Jo
  John: Jack
  Jonathan: Nathan
  Joseph: Joey
  Katherine: Kitty
  Katrina: Kat
  Kenneth: Ken
  Kimberley: Kim
  Kristen: Krissy
  Laura: Lori
  Lawrence: Larry
  Lewis: Lewie
  Lillian: Lilly
  Louis: Lou
  Louise: Lou
  Lucille: Lucy
  Margaret: Peg
  Martin: Marty
  Mary: Daisie
  Matthew: Matt
  Megan: Meg
  Michael: Mikey
  Michelle: Shelly
  Nathan: Nate
  Nathaniel: Nat
  Nicholas: Nick
  Nicole: Nicky
  Olive: Liv
  Oliver: Olly
  Oscar: Ozzy
  Pamela: Pam
  Patricia: Trish
  Patrick: Pat
  Peter: Pete
  Philippa: Pip
  Phillip: Phil
  Priscilla: Cilla
  Jacklyn: Jack
  Julia: Lea
  Kaitlin: Kat
  Quintin: Quinn
  Ann: Nancy
  Linda: Lynn
  Raphael: Ralph
  Francesca: Fran
  Gabriela: Gabby
  Gracia: Grace
  Jasmin: Jazz
  Judith: Judy
  Raymond: Ray
  Rebecca: Bec
  Richard: Dick
  Robert: Bobby
  Ronald: Ronnie
  Rosemary: Rose
  Samantha: Sam
  Samuel: Sammy
  Sarah: Sally
  Sharon: Shaza
  Simon: Sam
  Stephanie: Steph
  Stephen: Steve
  Steven: Steve
  Stewart: Stewie
  Susan: Sue
  Theodore: Ted
  Thomas: Tom
  Timothy: Tim
  Valerie: Val
  Veronica: Ronnie
  Victor: Vic
  Victoria: Tori
  Vincent: Vince
  Virginia: Ginny
  Walter: Walt
  William: Bill
  Zachary: Zack
  Zane: Bo
  Zoe: Zoey
  Melanie: Mel
  Natasha: Tasha
  Paula: Polly
  Rachel: Ray
  Wendy: Peggy
YAML;

  $name_generate_examples = <<<YAML
examples:
  -
    title: 'Mr'
    given: 'John'
    middle: 'Peter Mark'
    family: 'Doe'
    generational: 'Jnr.'
    credentials: 'B.Sc., Ph.D.'
    preferred: 'Joe'
    alternative: 'Lorem ipsum dolor'
  -
    title: ''
    given: 'JOAN'
    middle: 'SUE'
    family: 'SMITH'
    generational: ''
    credentials: ''
  -
    title: ''
    given: 'Prince'
    middle: ''
    family: ''
    generational: ''
    credentials: ''

YAML;

  $config_factory = \Drupal::configFactory();
  $name_generate_components_data = Yaml::parse($name_generate_components);
  $components_config = $config_factory->getEditable('name.generate.components');
  $components_config->set('components', $name_generate_components_data['components']);
  $components_config->set('gender', $name_generate_components_data['gender']);
  $components_config->save(TRUE);

  $name_generate_preferred_data = Yaml::parse($name_generate_preferred);
  $preferred_config = $config_factory->getEditable('name.generate.preferred');
  if ($preferred_config->isNew()) {
    $preferred_config->set('preferred', $name_generate_preferred_data['preferred']);
    $preferred_config->save(TRUE);
  }

  if ($examples = $config_factory->get('name.examples.default')->get('examples')) {
    $examples_config = $config_factory->getEditable('name.generate.examples');
    if (!empty($examples[0]['title'])) {
      $examples[0] += [
        'preferred' => 'Joe',
        'alternative' => 'Lorem ipsum dolor',
      ];
    }
    $examples_config->set('examples', $examples);
    $examples_config->save(TRUE);
    $old_config = $config_factory->getEditable('name.examples.default');
    $old_config->delete();
  }
  elseif ($config_factory->get('name.generate.examples')->isNew()) {
    $name_generate_examples_data = Yaml::parse($name_generate_examples);
    $examples_config = $config_factory->getEditable('name.generate.examples');
    $examples_config->set('examples', $name_generate_examples_data['examples']);
    $examples_config->save(TRUE);
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc