Drupal from 10.6.17 to 11.4.7
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the materio_flag module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fix flag configs with empty labels.
|
||||
*
|
||||
* Flag lists (flag_lists) can create relflag_* flag configs without a label.
|
||||
* Core 10 silently tolerated NULL labels, but core 11 typed
|
||||
* Html::escape() as string, which makes \Drupal::token()->getInfo() fatal
|
||||
* (the flag tokens build t('@flag flag link', ['@flag' => $flag->label()])).
|
||||
*
|
||||
* Give every flag a string label: the related flagging collection name when
|
||||
* available, the flag ID as a fallback.
|
||||
*/
|
||||
function materio_flag_update_10200(&$sandbox = NULL) {
|
||||
$flags = \Drupal::service('flag')->getAllFlags();
|
||||
$fixed = 0;
|
||||
foreach ($flags as $id => $flag) {
|
||||
$label = $flag->label();
|
||||
if (is_string($label) && $label !== '') {
|
||||
continue;
|
||||
}
|
||||
$new_label = $id;
|
||||
if (preg_match('/^relflag_(\d+)_/', $id, $matches)) {
|
||||
$collection = \Drupal::entityTypeManager()->getStorage('flagging_collection')->load($matches[1]);
|
||||
if ($collection && is_string($collection->label()) && $collection->label() !== '') {
|
||||
$new_label = $collection->label();
|
||||
}
|
||||
}
|
||||
$flag->set('label', $new_label)->save();
|
||||
$fixed++;
|
||||
}
|
||||
return t('@count flag(s) with an empty label have been fixed.', ['@count' => $fixed]);
|
||||
}
|
||||
Reference in New Issue
Block a user