|
5 | 5 | * Post update functions for Product. |
6 | 6 | */ |
7 | 7 |
|
| 8 | +use Drupal\Core\Entity\Entity\EntityFormDisplay; |
| 9 | + |
8 | 10 | /** |
9 | 11 | * Revert the Products view because of the updated permission. |
10 | 12 | */ |
@@ -102,33 +104,19 @@ function commerce_product_post_update_3() { |
102 | 104 | } |
103 | 105 |
|
104 | 106 | /** |
105 | | - * Revert the default product form display. |
| 107 | + * Expose the status field on every product form. |
106 | 108 | */ |
107 | 109 | 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(); |
131 | 121 | } |
132 | | - |
133 | | - return $message; |
134 | 122 | } |
0 commit comments