Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295812

Use null coalescing assignment operator

$
0
0

Problem/Motivation

For example,

A: in core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php, in function getNormalization,
$base['links'] = $base['links'] ?? $this->serializer->normalize($object->getLinks(), $format, $context)->omitIfEmpty();
could be changed in,
$base['links'] ??= $this->serializer->normalize($object->getLinks(), $format, $context)->omitIfEmpty();

B: in core/modules/layout_discovery/layout_discovery.module, in function template_preprocess_layout,

    if (!isset($variables['content'][$name]['#attributes'])) {
      $variables['content'][$name]['#attributes'] = [];
    }

could be changed in,
$variables['content'][$name]['#attributes'] ??= [];

Steps to reproduce

Proposed resolution

From #2 in #3418494: Use null coalescing assignment operator: case $A = $A ?? $B;,

.... assume there are many similar changes we could make across all of core, and ideally a coding standards sniff we could enable to prevent this code from creeping back in.

Ideally we would change all instances of this across core in one go,

Therefore trying to do this with some sed commands.

Remaining tasks

A: #3418494: Use null coalescing assignment operator: case $A = $A ?? $B;
B: #3423310: Use null coalescing assignment operator: multilignes case.

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 295812

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>