Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     /** @var OrderInterface $order */
     $order = $this->entity;
     $original = clone $order;
     // Build list of changes to be applied.
     $panes = $this->orderPaneManager->getPanes();
     foreach ($panes as $pane) {
         if ($pane instanceof EditableOrderPanePluginInterface) {
             $pane->submitForm($order, $form, $form_state);
         }
     }
     $log = array();
     foreach (array_keys($order->getFieldDefinitions()) as $key) {
         if ($original->{$key}->value !== $order->{$key}->value) {
             if (!is_array($order->{$key}->value)) {
                 $log[$key] = array('old' => $original->{$key}->value, 'new' => $order->{$key}->value);
             }
         }
     }
     // Load line items again, since some may have been updated by the form.
     $order->line_items = $order->getLineItems();
     $order->logChanges($log);
     $order->save();
     drupal_set_message($this->t('Order changes saved.'));
 }
 /**
  * {@inheritdoc}
  */
 public function buildComponents(array &$build, array $entities, array $displays, $view_mode)
 {
     parent::buildComponents($build, $entities, $displays, $view_mode);
     $panes = $this->orderPaneManager->getPanes();
     $components = $displays['uc_order']->getComponents();
     foreach ($entities as $id => $order) {
         foreach ($panes as $pane_id => $pane) {
             // Skip panes that are hidden in "Manage display".
             if (!isset($components[$pane_id])) {
                 continue;
             }
             if ($contents = $pane->view($order, $view_mode)) {
                 $build[$id][$pane_id] = array('#prefix' => '<div class="order-pane ' . $pane->getClasses() . '" id="order-pane-' . $pane_id . '">', '#suffix' => '</div>');
                 if ($title = $pane->getTitle()) {
                     $build[$id][$pane_id]['title'] = array('#prefix' => '<div class="order-pane-title">', '#markup' => $title . ':', '#suffix' => '</div>');
                 }
                 $build[$id][$pane_id]['pane'] = $contents;
             }
         }
     }
 }