|
2 | 2 |
|
3 | 3 | namespace Drupal\commerce_product\Form; |
4 | 4 |
|
5 | | -use Drupal\commerce_product\Entity\ProductInterface; |
6 | 5 | use Drupal\Core\Datetime\DateFormatterInterface; |
7 | 6 | use Drupal\Component\Datetime\TimeInterface; |
8 | 7 | use Drupal\Core\Entity\ContentEntityForm; |
@@ -85,13 +84,21 @@ public function form(array $form, FormStateInterface $form_state) { |
85 | 84 | $form['#tree'] = TRUE; |
86 | 85 | $form['#theme'] = ['commerce_product_form']; |
87 | 86 | $form['#attached']['library'][] = 'commerce_product/form'; |
88 | | - $form['#entity_builders']['update_status'] = [get_class($this), 'updateStatus']; |
89 | 87 | // Changed must be sent to the client, for later overwrite error checking. |
90 | 88 | $form['changed'] = [ |
91 | 89 | '#type' => 'hidden', |
92 | 90 | '#default_value' => $product->getChangedTime(), |
93 | 91 | ]; |
94 | 92 |
|
| 93 | + $form['footer'] = [ |
| 94 | + '#type' => 'container', |
| 95 | + '#weight' => 99, |
| 96 | + '#attributes' => [ |
| 97 | + 'class' => ['product-form-footer'], |
| 98 | + ], |
| 99 | + ]; |
| 100 | + $form['status']['#group'] = 'footer'; |
| 101 | + |
95 | 102 | $last_saved = t('Not saved yet'); |
96 | 103 | if (!$product->isNew()) { |
97 | 104 | $last_saved = $this->dateFormatter->format($product->getChangedTime(), 'short'); |
@@ -208,74 +215,6 @@ public static function hideEmptyVisibilitySettings(array $form) { |
208 | 215 | return $form; |
209 | 216 | } |
210 | 217 |
|
211 | | - /** |
212 | | - * Entity builder: updates the product status with the submitted value. |
213 | | - * |
214 | | - * @param string $entity_type |
215 | | - * The entity type. |
216 | | - * @param \Drupal\commerce_product\Entity\ProductInterface $product |
217 | | - * The product updated with the submitted values. |
218 | | - * @param array $form |
219 | | - * The complete form array. |
220 | | - * @param \Drupal\Core\Form\FormStateInterface $form_state |
221 | | - * The current state of the form. |
222 | | - * |
223 | | - * @see \Drupal\node\NodeForm::form() |
224 | | - */ |
225 | | - public static function updateStatus($entity_type, ProductInterface $product, array $form, FormStateInterface $form_state) { |
226 | | - $element = $form_state->getTriggeringElement(); |
227 | | - if (isset($element['#published_status'])) { |
228 | | - $product->setPublished($element['#published_status']); |
229 | | - } |
230 | | - } |
231 | | - |
232 | | - /** |
233 | | - * {@inheritdoc} |
234 | | - */ |
235 | | - protected function actions(array $form, FormStateInterface $form_state) { |
236 | | - $element = parent::actions($form, $form_state); |
237 | | - /** @var \Drupal\commerce_product\Entity\ProductInterface $product */ |
238 | | - $product = $this->entity; |
239 | | - |
240 | | - $element['delete']['#access'] = $product->access('delete'); |
241 | | - $element['delete']['#weight'] = 100; |
242 | | - // Add a "Publish" button. |
243 | | - $element['publish'] = $element['submit']; |
244 | | - $element['publish']['#published_status'] = TRUE; |
245 | | - $element['publish']['#dropbutton'] = 'save'; |
246 | | - $element['publish']['#weight'] = 0; |
247 | | - // Add an "Unpublish" button. |
248 | | - $element['unpublish'] = $element['submit']; |
249 | | - $element['unpublish']['#published_status'] = FALSE; |
250 | | - $element['unpublish']['#dropbutton'] = 'save'; |
251 | | - $element['unpublish']['#weight'] = 10; |
252 | | - // isNew | prev status » primary & publish label & unpublish label |
253 | | - // 1 | 1 » publish & Save and publish & Save as unpublished |
254 | | - // 1 | 0 » unpublish & Save and publish & Save as unpublished |
255 | | - // 0 | 1 » publish & Save and keep published & Save and unpublish |
256 | | - // 0 | 0 » unpublish & Save and keep unpublished & Save and publish. |
257 | | - if ($product->isNew()) { |
258 | | - $element['publish']['#value'] = $this->t('Save and publish'); |
259 | | - $element['unpublish']['#value'] = $this->t('Save as unpublished'); |
260 | | - } |
261 | | - else { |
262 | | - $element['publish']['#value'] = $product->isPublished() ? $this->t('Save and keep published') : $this->t('Save and publish'); |
263 | | - $element['unpublish']['#value'] = !$product->isPublished() ? $this->t('Save and keep unpublished') : $this->t('Save and unpublish'); |
264 | | - } |
265 | | - // Set the primary button based on the published status. |
266 | | - if ($product->isPublished()) { |
267 | | - unset($element['unpublish']['#button_type']); |
268 | | - } |
269 | | - else { |
270 | | - unset($element['publish']['#button_type']); |
271 | | - $element['unpublish']['#weight'] = -10; |
272 | | - } |
273 | | - // Hide the now unneeded "Save" button. |
274 | | - $element['submit']['#access'] = FALSE; |
275 | | - |
276 | | - return $element; |
277 | | - } |
278 | | - |
279 | 218 | /** |
280 | 219 | * {@inheritdoc} |
281 | 220 | */ |
|
0 commit comments