Issue #1704864 by nick_schuch, Stalski, larowlan, kostyashupenko, andymartha, xjm, webchick, zuuperman, tim.plunkett, catch, alexverb, irawan, ling-drupal: Add a "Required" and "Show by default" option for "Text area with a summary" field/widget
2019-06-28 02:01:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Contains post update hooks for the text module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Drupal\Core\Config\Entity\ConfigEntityUpdater;
|
|
|
|
use Drupal\Core\Entity\Display\EntityDisplayInterface;
|
|
|
|
use Drupal\text\Plugin\Field\FieldWidget\TextareaWithSummaryWidget;
|
|
|
|
|
|
|
|
/**
|
2020-03-11 20:58:38 +00:00
|
|
|
* Implements hook_removed_post_updates().
|
Issue #1704864 by nick_schuch, Stalski, larowlan, kostyashupenko, andymartha, xjm, webchick, zuuperman, tim.plunkett, catch, alexverb, irawan, ling-drupal: Add a "Required" and "Show by default" option for "Text area with a summary" field/widget
2019-06-28 02:01:21 +00:00
|
|
|
*/
|
2020-03-11 20:58:38 +00:00
|
|
|
function text_removed_post_updates() {
|
|
|
|
return [
|
|
|
|
'text_post_update_add_required_summary_flag' => '9.0.0',
|
|
|
|
];
|
2019-12-16 15:18:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update text_with_summary widgets to add summary required flags.
|
|
|
|
*/
|
|
|
|
function text_post_update_add_required_summary_flag_form_display(&$sandbox = NULL) {
|
|
|
|
$config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
|
Issue #1704864 by nick_schuch, Stalski, larowlan, kostyashupenko, andymartha, xjm, webchick, zuuperman, tim.plunkett, catch, alexverb, irawan, ling-drupal: Add a "Required" and "Show by default" option for "Text area with a summary" field/widget
2019-06-28 02:01:21 +00:00
|
|
|
/** @var \Drupal\Core\Field\WidgetPluginManager $field_widget_manager */
|
|
|
|
$field_widget_manager = \Drupal::service('plugin.manager.field.widget');
|
|
|
|
|
|
|
|
$widget_callback = function (EntityDisplayInterface $display) use ($field_widget_manager) {
|
|
|
|
$needs_save = FALSE;
|
|
|
|
foreach ($display->getComponents() as $field_name => $component) {
|
|
|
|
if (empty($component['type'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$plugin_definition = $field_widget_manager->getDefinition($component['type'], FALSE);
|
|
|
|
if (is_a($plugin_definition['class'], TextareaWithSummaryWidget::class, TRUE)) {
|
|
|
|
$component['settings']['show_summary'] = FALSE;
|
|
|
|
$display->setComponent($field_name, $component);
|
|
|
|
$needs_save = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $needs_save;
|
|
|
|
};
|
|
|
|
|
|
|
|
$config_entity_updater->update($sandbox, 'entity_form_display', $widget_callback);
|
|
|
|
}
|