Skip to content

Commit 202b8f8

Browse files
committed
Issue #2898258 followup: Improve the update hook by copying the one from core.
1 parent 3bc1b88 commit 202b8f8

1 file changed

Lines changed: 14 additions & 26 deletions

File tree

modules/product/commerce_product.post_update.php

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Post update functions for Product.
66
*/
77

8+
use Drupal\Core\Entity\Entity\EntityFormDisplay;
9+
810
/**
911
* Revert the Products view because of the updated permission.
1012
*/
@@ -102,33 +104,19 @@ function commerce_product_post_update_3() {
102104
}
103105

104106
/**
105-
* Revert the default product form display.
107+
* Expose the status field on every product form.
106108
*/
107109
function commerce_product_post_update_4() {
108-
/** @var \Drupal\commerce\Config\ConfigUpdaterInterface $config_updater */
109-
$config_updater = \Drupal::service('commerce.config_updater');
110-
111-
$views = [
112-
'core.entity_form_display.commerce_product.default.default',
113-
];
114-
$result = $config_updater->revert($views, TRUE);
115-
116-
$success_results = $result->getSucceeded();
117-
$failure_results = $result->getFailed();
118-
$message = '';
119-
if ($success_results) {
120-
$message = t('Succeeded:') . '<br>';
121-
foreach ($success_results as $success_message) {
122-
$message .= $success_message . '<br>';
123-
}
124-
$message .= '<br>';
125-
}
126-
if ($failure_results) {
127-
$message .= t('Failed:') . '<br>';
128-
foreach ($failure_results as $failure_message) {
129-
$message .= $failure_message . '<br>';
130-
}
110+
$query = \Drupal::entityQuery('entity_form_display')->condition('targetEntityType', 'commerce_product');
111+
$ids = $query->execute();
112+
$form_displays = EntityFormDisplay::loadMultiple($ids);
113+
foreach ($form_displays as $id => $form_display) {
114+
/** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $form_display */
115+
$form_display->setComponent('status', [
116+
'type' => 'boolean_checkbox',
117+
'settings' => [
118+
'display_label' => TRUE,
119+
],
120+
])->save();
131121
}
132-
133-
return $message;
134122
}

0 commit comments

Comments
 (0)