Skip to content
Snippets Groups Projects
Commit 63f80777 authored by John Voskuilen's avatar John Voskuilen
Browse files

Issue #2919482: Clean code - phpcs, shorthand ?? code

parent c24eaac0
No related branches found
No related tags found
No related merge requests found
Pipeline #85557 canceled
Showing
with 23 additions and 23 deletions
...@@ -78,9 +78,9 @@ class WorkflowAccessRoleForm extends WorkflowConfigTransitionFormBase { ...@@ -78,9 +78,9 @@ class WorkflowAccessRoleForm extends WorkflowConfigTransitionFormBase {
$count = 0; $count = 0;
foreach (workflow_access_get_workflow_access_by_sid($sid) as $rid => $access) { foreach (workflow_access_get_workflow_access_by_sid($sid) as $rid => $access) {
$count++; $count++;
$view[$rid] = ($access['grant_view']) ? $rid : 0; $view[$rid] = $access['grant_view'] ? $rid : 0;
$update[$rid] = ($access['grant_update']) ? $rid : 0; $update[$rid] = $access['grant_update'] ? $rid : 0;
$delete[$rid] = ($access['grant_delete']) ? $rid : 0; $delete[$rid] = $access['grant_delete'] ? $rid : 0;
} }
// Allow view grants by default for anonymous and authenticated users, // Allow view grants by default for anonymous and authenticated users,
// if no grants were set up earlier. // if no grants were set up earlier.
......
...@@ -167,7 +167,7 @@ function workflow_access_node_access_records(NodeInterface $node) { ...@@ -167,7 +167,7 @@ function workflow_access_node_access_records(NodeInterface $node) {
// Get 'author' of this entity. Some entities (e.g., taxonomy_term) // Get 'author' of this entity. Some entities (e.g., taxonomy_term)
// do not have a uid. But then again: node_access is only for nodes... // do not have a uid. But then again: node_access is only for nodes...
/** @var \Drupal\node\NodeInterface $translation */ /** @var \Drupal\node\NodeInterface $translation */
$uid = ($translation->getOwnerId()) ? (int) $translation->getOwnerId() : 0; $uid = (int) $translation->getOwnerId() ?? 0;
$workflow_transitions = []; $workflow_transitions = [];
if (isset($translation->workflow_transitions)) { if (isset($translation->workflow_transitions)) {
......
...@@ -519,7 +519,7 @@ class WorkflowTransitionElement extends FormElement { ...@@ -519,7 +519,7 @@ class WorkflowTransitionElement extends FormElement {
$fields = WorkflowManager::getAttachedFields('workflow_transition', $transition->bundle()); $fields = WorkflowManager::getAttachedFields('workflow_transition', $transition->bundle());
/** @var \Drupal\Core\Field\Entity\BaseFieldOverride $field */ /** @var \Drupal\Core\Field\Entity\BaseFieldOverride $field */
foreach ($fields as $field_name => $field) { foreach ($fields as $field_name => $field) {
$user_input = isset($form_state->getUserInput()[$field_name]) ? $form_state->getUserInput()[$field_name] : []; $user_input = $form_state->getUserInput()[$field_name] ?? [];
if (isset($item[$field_name])) { if (isset($item[$field_name])) {
// On Workflow Form (e.g., history tab, block). // On Workflow Form (e.g., history tab, block).
// @todo In latest tests, this line seems not necessary. // @todo In latest tests, this line seems not necessary.
...@@ -548,7 +548,7 @@ class WorkflowTransitionElement extends FormElement { ...@@ -548,7 +548,7 @@ class WorkflowTransitionElement extends FormElement {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getInfo() { public function getInfo() {
$class = get_class($this); $class = static::class;
return [ return [
'#input' => TRUE, '#input' => TRUE,
'#return_value' => 1, '#return_value' => 1,
......
...@@ -432,8 +432,8 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface { ...@@ -432,8 +432,8 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
$config_transitions = []; $config_transitions = [];
// Get filters on 'from' states, 'to' states, roles. // Get filters on 'from' states, 'to' states, roles.
$from_sid = isset($conditions['from_sid']) ? $conditions['from_sid'] : FALSE; $from_sid = $conditions['from_sid'] ?? FALSE;
$to_sid = isset($conditions['to_sid']) ? $conditions['to_sid'] : FALSE; $to_sid = $conditions['to_sid'] ?? FALSE;
// Get valid states + creation state. // Get valid states + creation state.
$states = $this->getStates('CREATION'); $states = $this->getStates('CREATION');
......
...@@ -149,8 +149,8 @@ interface WorkflowInterface { ...@@ -149,8 +149,8 @@ interface WorkflowInterface {
* @param array|null $ids * @param array|null $ids
* Array of Transitions IDs. If NULL, show all transitions. * Array of Transitions IDs. If NULL, show all transitions.
* @param array $conditions * @param array $conditions
* $conditions['from_sid'] : if provided, a 'from' State ID. * $conditions['from_sid']: if provided, a 'from' State ID.
* $conditions['to_sid'] : if provided, a 'to' state ID. * $conditions['to_sid']: if provided, a 'to' state ID.
* *
* @return \Drupal\workflow\Entity\WorkflowConfigTransition[] * @return \Drupal\workflow\Entity\WorkflowConfigTransition[]
*/ */
......
...@@ -220,7 +220,7 @@ class WorkflowScheduledTransition extends WorkflowTransition { ...@@ -220,7 +220,7 @@ class WorkflowScheduledTransition extends WorkflowTransition {
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = []; $fields = [];
// Add the specific ID-field : tid vs. hid. // Add the specific ID-field: tid vs. hid.
$fields['tid'] = BaseFieldDefinition::create('integer') $fields['tid'] = BaseFieldDefinition::create('integer')
->setLabel(t('Transition ID')) ->setLabel(t('Transition ID'))
->setDescription(t('The transition ID.')) ->setDescription(t('The transition ID.'))
......
...@@ -119,7 +119,7 @@ class WorkflowState extends ConfigEntityBase { ...@@ -119,7 +119,7 @@ class WorkflowState extends ConfigEntityBase {
*/ */
public function __construct(array $values = [], $entityType = 'workflow_state') { public function __construct(array $values = [], $entityType = 'workflow_state') {
// Please be aware that $entity_type_id and $entityType are different things! // Please be aware that $entity_type_id and $entityType are different things!
$sid = isset($values['id']) ? $values['id'] : ''; $sid = $values['id'] ?? '';
// Keep official name and external name equal. Both are required. // Keep official name and external name equal. Both are required.
// @todo Still needed? test import, manual creation, programmatic creation, etc. // @todo Still needed? test import, manual creation, programmatic creation, etc.
......
...@@ -178,12 +178,12 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition ...@@ -178,12 +178,12 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
*/ */
public function setValues($to_sid, $uid = NULL, $timestamp = NULL, $comment = '', $force_create = FALSE) { public function setValues($to_sid, $uid = NULL, $timestamp = NULL, $comment = '', $force_create = FALSE) {
// Normally, the values are passed in an array, and set in parent::__construct, but we do it ourselves. // Normally, the values are passed in an array, and set in parent::__construct, but we do it ourselves.
$uid = ($uid === NULL) ? workflow_current_user()->id() : $uid; $uid = $uid ?? workflow_current_user()->id();
$from_sid = $this->getFromSid(); $from_sid = $this->getFromSid();
$this->set('to_sid', $to_sid); $this->set('to_sid', $to_sid);
$this->setOwnerId($uid); $this->setOwnerId($uid);
$this->setTimestamp($timestamp == NULL ? \Drupal::time()->getRequestTime() : $timestamp); $this->setTimestamp($timestamp ?? \Drupal::time()->getRequestTime());
$this->setComment($comment); $this->setComment($comment);
// If constructor is called with new() and arguments. // If constructor is called with new() and arguments.
...@@ -1103,8 +1103,8 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition ...@@ -1103,8 +1103,8 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
'%sid2' => ($to_sid || !$this->getToState()) ? $to_sid : $this->getToState()->label(), '%sid2' => ($to_sid || !$this->getToState()) ? $to_sid : $this->getToState()->label(),
'%entity_id' => $this->getTargetEntityId(), '%entity_id' => $this->getTargetEntityId(),
'%entity_label' => $entity ? $entity->label() : '', '%entity_label' => $entity ? $entity->label() : '',
'@entity_type' => ($entity) ? $entity->getEntityTypeId() : '', '@entity_type' => $entity ? $entity->getEntityTypeId() : '',
'@entity_type_label' => ($entity) ? $entity->getEntityType()->getLabel() : '', '@entity_type_label' => $entity ? $entity->getEntityType()->getLabel() : '',
'link' => ($this->getTargetEntityId() && $this->getTargetEntity()->hasLinkTemplate('canonical')) ? $this->getTargetEntity()->toLink($this->t('View'))->toString() : '', 'link' => ($this->getTargetEntityId() && $this->getTargetEntity()->hasLinkTemplate('canonical')) ? $this->getTargetEntity()->toLink($this->t('View'))->toString() : '',
]; ];
($type == 'error') ? \Drupal::logger('workflow')->error($message, $t_args) ($type == 'error') ? \Drupal::logger('workflow')->error($message, $t_args)
......
...@@ -87,7 +87,7 @@ abstract class WorkflowStateActionBase extends ConfigurableActionBase implements ...@@ -87,7 +87,7 @@ abstract class WorkflowStateActionBase extends ConfigurableActionBase implements
return NULL; return NULL;
} }
$to_sid = isset($config['to_sid']) ? $config['to_sid'] : ''; $to_sid = $config['to_sid'] ?? '';
// Get the Comment. Parse the $comment variables. // Get the Comment. Parse the $comment variables.
$comment_string = $this->configuration['comment']; $comment_string = $this->configuration['comment'];
$comment = $this->t($comment_string, [ $comment = $this->t($comment_string, [
......
...@@ -68,7 +68,7 @@ class WorkflowItem extends ListItemBase { ...@@ -68,7 +68,7 @@ class WorkflowItem extends ListItemBase {
$definition['settings']['target_type'] = 'workflow_transition'; $definition['settings']['target_type'] = 'workflow_transition';
// Definitions vary by entity type and bundle, so key them accordingly. // Definitions vary by entity type and bundle, so key them accordingly.
$key = $definition['settings']['target_type'] . ':'; $key = $definition['settings']['target_type'] . ':';
$key .= isset($definition['settings']['target_bundle']) ? $definition['settings']['target_bundle'] : ''; $key .= $definition['settings']['target_bundle'] ?? '';
if (!isset($propertyDefinitions[$key])) { if (!isset($propertyDefinitions[$key])) {
...@@ -241,7 +241,7 @@ class WorkflowItem extends ListItemBase { ...@@ -241,7 +241,7 @@ class WorkflowItem extends ListItemBase {
'#rows' => count($allowed_values), '#rows' => count($allowed_values),
'#access' => ($wid) ? TRUE : FALSE, // User can see the data, '#access' => ($wid) ? TRUE : FALSE, // User can see the data,
'#disabled' => TRUE, // .. but cannot change them. '#disabled' => TRUE, // .. but cannot change them.
'#element_validate' => [[get_class($this), 'validateAllowedValues']], '#element_validate' => [[static::class, 'validateAllowedValues']],
'#field_has_data' => $has_data, '#field_has_data' => $has_data,
'#field_name' => $this->getFieldDefinition()->getName(), '#field_name' => $this->getFieldDefinition()->getName(),
......
...@@ -23,7 +23,7 @@ class WorkflowState extends ManyToOne { ...@@ -23,7 +23,7 @@ class WorkflowState extends ManyToOne {
*/ */
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options); parent::init($view, $display, $options);
$wid = isset($this->definition['wid']) ? $this->definition['wid'] : ''; $wid = $this->definition['wid'] ?? '';
$grouped = isset($options['group_info']['widget']) ? $options['group_info']['widget'] == 'select' : FALSE; $grouped = isset($options['group_info']['widget']) ? $options['group_info']['widget'] == 'select' : FALSE;
$this->valueOptions = workflow_get_workflow_state_names($wid, $grouped); $this->valueOptions = workflow_get_workflow_state_names($wid, $grouped);
} }
......
...@@ -260,7 +260,7 @@ class WorkflowStateListBuilder extends DraggableListBuilder { ...@@ -260,7 +260,7 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
// @todo D8: enable WorkflowState machine_name as interactive element. // @todo D8: enable WorkflowState machine_name as interactive element.
foreach ($form_state->getValue($this->entitiesKey) as $sid => $value) { foreach ($form_state->getValue($this->entitiesKey) as $sid => $value) {
/** @var \Drupal\workflow\Entity\WorkflowState $state */ /** @var \Drupal\workflow\Entity\WorkflowState $state */
$state = isset($this->entities[$sid]) ? $this->entities[$sid] : NULL; $state = $this->entities[$sid] ?? NULL;
// State is de-activated (reassigning current content). // State is de-activated (reassigning current content).
if ($state && $state->isActive() && !$value['status']) { if ($state && $state->isActive() && !$value['status']) {
......
...@@ -93,7 +93,7 @@ trait WorkflowTypeAttributeTrait { ...@@ -93,7 +93,7 @@ trait WorkflowTypeAttributeTrait {
} }
elseif (is_object($value)) { elseif (is_object($value)) {
// In WorkflowTransition. // In WorkflowTransition.
$wid = isset($value->getValue()[0]['target_id']) ? $value->getValue()[0]['target_id'] : ''; $wid = $value->getValue()[0]['target_id'] ?? '';
$this->wid = $wid; $this->wid = $wid;
} }
else { else {
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
</div> </div>
{% if comment %} {% if comment %}
<div{{ field_attributes.addClass(field_classes) }}> <div{{ field_attributes.addfield_classes) }}>
<div{{ label_attributes.addClass(title_classes) }}>{% trans %}Comment{% endtrans %}</div> <div{{ label_attributes.addClass(title_classes) }}>{% trans %}Comment{% endtrans %}</div>
<div{{ value_attributes.addClass(item_classes) }}>{{ comment }}</div> <div{{ value_attributes.addClass(item_classes) }}>{{ comment }}</div>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment