Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
NameListFormat
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 uri
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 isLocked
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 listSettings
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\name\Entity;
6
7use Drupal\Core\Config\Entity\ConfigEntityBase;
8
9/**
10 * Defines the Name List Format configuration entity class.
11 *
12 * @ConfigEntityType(
13 *   id = "name_list_format",
14 *   label = @Translation("Name list format"),
15 *   handlers = {
16 *     "form" = {
17 *       "add" = "Drupal\name\Form\NameListFormatForm",
18 *       "edit" = "Drupal\name\Form\NameListFormatForm",
19 *       "delete" = "Drupal\name\Form\NameListFormatDeleteConfirm"
20 *     },
21 *     "access" = "Drupal\name\Access\NameFormatAccessHandler",
22 *     "list_builder" = "Drupal\name\ListBuilder\NameListFormatListBuilder"
23 *   },
24 *   config_prefix = "name_list_format",
25 *   fieldable = FALSE,
26 *   entity_keys = {
27 *     "id" = "id",
28 *     "label" = "label",
29 *     "uuid" = "uuid"
30 *   },
31 *   config_export = {
32 *     "id",
33 *     "uuid",
34 *     "langcode",
35 *     "label",
36 *     "locked",
37 *     "status",
38 *     "delimiter",
39 *     "and",
40 *     "delimiter_precedes_last",
41 *     "el_al_min",
42 *     "el_al_first",
43 *   },
44 *   links = {
45 *     "edit-form" = "/admin/config/regional/name/list/manage/{name_list_format}",
46 *     "delete-form" = "/admin/config/regional/name/list/manage/{name_list_format}/delete"
47 *   }
48 * )
49 */
50class NameListFormat extends ConfigEntityBase implements NameListFormatInterface {
51
52  /**
53   * The name format machine name.
54   *
55   * @var string
56   */
57  public $id;
58
59  /**
60   * The name format UUID.
61   *
62   * @var string
63   */
64  public $uuid;
65
66  /**
67   * The human-readable name of the name format entity.
68   *
69   * @var string
70   */
71  public $label;
72
73  /**
74   * The locked status of this name format.
75   *
76   * @var bool
77   */
78  public $locked = FALSE;
79
80  /**
81   * The delimiter of this name list format.
82   *
83   * @var string
84   */
85  public $delimiter = ', ';
86
87  /**
88   * The final delimiter type of this name list format.
89   *
90   * Valid options include:
91   * - text: textual (i.e. 'and').
92   * - symbol: ampersand.
93   *
94   * @var string
95   */
96  public $and = 'text';
97
98  /**
99   * The method of handling the final delimiter before the and indicator.
100   *
101   * Valid options include:
102   * - never: Never combine
103   * - always: Always combine
104   * - contextual: Combine with 3 or more names.
105   *
106   * @var string
107   */
108  public $delimiter_precedes_last = 'never';
109
110  /**
111   * Reduce list limit of this name list format.
112   *
113   * This specifies a limit on the number of names to display. After this
114   * limit, names are removed and the abbreviation et al is appended. This
115   * Latin abbreviation of et alii means "and others".
116   *
117   * @var int
118   */
119  public $el_al_min = 3;
120
121  /**
122   * Number of names to show when list is reduced of this name list format.
123   *
124   * This specifies a limit on the number of names to display. After this
125   * limit, names are removed and the abbreviation et al is appended. This
126   * Latin abbreviation of et alii means "and others".
127   *
128   * @var int
129   */
130  public $el_al_first = 1;
131
132  /**
133   * {@inheritdoc}
134   */
135  public function uri() {
136    return [
137      'path' => 'admin/config/regional/name/list/manage/' . $this->id(),
138      'options' => [
139        'entity_type' => $this->getEntityType(),
140        'entity' => $this,
141      ],
142    ];
143  }
144
145  /**
146   * {@inheritdoc}
147   */
148  public function isLocked() {
149    return (bool) $this->locked;
150  }
151
152  /**
153   * {@inheritdoc}
154   */
155  public function listSettings() {
156    $el_al_first = $this->el_al_first;
157    if ($el_al_first > $this->el_al_min) {
158      $el_al_first = $this->el_al_min;
159    }
160    return [
161      'delimiter' => $this->delimiter,
162      'and' => $this->and,
163      'delimiter_precedes_last' => $this->delimiter_precedes_last,
164      'el_al_min' => $this->el_al_min,
165      'el_al_first' => $el_al_first,
166    ];
167  }
168
169}