Skip to content

Commit

Permalink
Use null coalesce operator instead of ternary operator
Browse files Browse the repository at this point in the history
  • Loading branch information
WengerK committed Jul 27, 2022
1 parent a2bc463 commit 7019ab6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@
"license": "GPL-2.0-or-later",
"require-dev": {
"drupal/coder": "^8.3.1"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
2 changes: 1 addition & 1 deletion inc/tokens.inc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function template_whisperer_tokens($type, $tokens, array $data, array $options,

foreach ($tokens as $name => $original) {
preg_match('/^.*?:(.*?)(:(.*)$|$)/', $name, $matches);
$action = isset($matches[1]) ? $matches[1] : '';
$action = $matches[1] ?? '';
$rest = isset($matches[2]) ? ltrim($matches[2], ':') : '';

switch ($action) {
Expand Down
4 changes: 2 additions & 2 deletions src/Form/TemplateWhispererSuggestionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function form(array $form, FormStateInterface $form_state) {
$form['name'] = [
'#title' => $this->t('Name'),
'#type' => 'textfield',
'#default_value' => isset($entity->name) ? $entity->name : NULL,
'#default_value' => $entity->name ?? NULL,
'#description' => $this->t('The human-readable name. Will appear in the field widget.'),
'#size' => 50,
'#required' => TRUE,
Expand All @@ -64,7 +64,7 @@ public function form(array $form, FormStateInterface $form_state) {
$form['suggestion'] = [
'#title' => $this->t('Suggestion'),
'#type' => 'textfield',
'#default_value' => isset($entity->suggestion) ? $entity->suggestion : NULL,
'#default_value' => $entity->suggestion ?? NULL,
'#description' => $this->t('A unique suggestion for this template whisperer. It must only contain lowercase letters, numbers, and underscores. E.g. <code>news_list</code>'),
'#required' => TRUE,
'#size' => 50,
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Field/FieldType/TemplateWhispererFieldItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
'#type' => 'checkboxes',
'#title' => $this->t('Available Suggestions'),
'#options' => $whisperers,
'#default_value' => isset($settings['handler']['suggestions']) ? $settings['handler']['suggestions'] : [],
'#default_value' => $settings['handler']['suggestions'] ?? [],
'#description' => $this->t('The suggestion(s) that can be referenced through this field. Leave empty to allow all.'),
];

Expand Down

0 comments on commit 7019ab6

Please sign in to comment.