/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); // The subscriptions field has properties which are set to NULL by ordinary // saving, which is wrong. The Subscriber::(un)subscribe() methods save the // values correctly. For each newsletter ID we check if it exists in // current subscriptions and new subscriptions respectively. $current_subscriptions = $this->entity->getSubscribedNewsletterIds(); $subscription_values = $form_state->getValue('subscriptions'); $new_subscriptions = array(); foreach ($subscription_values as $subscription_value) { array_push($new_subscriptions, $subscription_value['target_id']); } foreach (array_keys(simplenews_newsletter_get_visible()) as $newsletter) { if (in_array($newsletter, $current_subscriptions) && !in_array($newsletter, $new_subscriptions)) { $this->entity->unsubscribe($newsletter); } elseif (!in_array($newsletter, $current_subscriptions) && in_array($newsletter, $new_subscriptions)) { $this->entity->subscribe($newsletter); } } $form_state->setRedirect('view.simplenews_subscribers.page_1'); if ($this->entity->isNew()) { drupal_set_message($this->t('Subscriber %label has been added.', array('%label' => $this->entity->label()))); } else { drupal_set_message($this->t('Subscriber %label has been updated.', array('%label' => $this->entity->label()))); } }
/** * {@inheritdoc} */ public function validate(array $form, FormStateInterface $form_state) { if (!$this->pathValidator->isValid($form_state->getValue('path'))) { $form_state->setErrorByName('path', $this->t('The shortcut must correspond to a valid path on the site.')); } parent::validate($form, $form_state); }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { $actions = parent::actions($form, $form_state); $actions['submit']['#value'] = $this->t('Save task'); $actions['submit']['#access'] = \Drupal::currentUser()->hasPermission('administer tmgmt') || \Drupal::currentUser()->hasPermission('administer translation tasks'); return $actions; }
/** * Overrides \Drupal\Core\Entity\EntityFormController::submit(). */ public function submit(array $form, array &$form_state) { // Build the entity object from the submitted values. $entity = parent::submit($form, $form_state); $form_state['redirect_route']['route_name'] = 'foo_bar.list'; return $entity; }
/** * {@inheritdoc} */ public function validate(array $form, FormStateInterface $form_state) { if (!shortcut_valid_link($form_state['values']['path'])) { $form_state->setErrorByName('path', $this->t('The shortcut must correspond to a valid path on the site.')); } parent::validate($form, $form_state); }
/** * {@inheritdoc} */ public function actions(array $form, FormStateInterface $form_state) { $actions = parent::actions($form, $form_state); if ($this->entity->isNew()) { $actions['submit']['#value'] = $this->t('Create Flagging'); } else { $actions['submit']['#value'] = $this->t('Update Flagging'); } // Customize the delete link. if (isset($actions['delete'])) { // @todo Why does the access call always fail? unset($actions['delete']['#access']); $actions['delete']['#title'] = $this->t('Delete Flagging'); // Build the delete url from route. We need to build this manually // otherwise Drupal will try to build the flagging entity's delete-form // link. Since that route doesn't use the flagging ID, Drupal can't build // the link for us. $route_params = [ 'flag' => $this->entity->getFlagId(), 'entity_id' => $this->entity->getFlaggableId(), 'destination' => \Drupal::request()->get('destination'), ]; $url = Url::fromRoute('flag.confirm_unflag', $route_params); $actions['delete']['#url'] = $url; } return $actions; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { /* @var \Drupal\commerce_order\Entity\Order $order */ $order = $this->entity; $currentUser = $this->currentUser(); $form['advanced'] = [ '#type' => 'vertical_tabs', '#attributes' => ['class' => ['entity-meta']], '#weight' => 99, ]; $form = parent::form($form, $form_state); $form['order_status'] = [ '#type' => 'details', '#title' => t('Order status'), '#group' => 'advanced', '#attributes' => [ 'class' => ['order-form-order-status'], ], '#attached' => [ 'library' => ['commerce_order/drupal.commerce_order'], ], '#weight' => 90, '#optional' => TRUE, ]; if (isset($form['status'])) { $form['status']['#group'] = 'order_status'; } // Order authoring information for administrators. $form['author'] = [ '#type' => 'details', '#title' => t('Authoring information'), '#group' => 'advanced', '#attributes' => [ 'class' => ['order-form-author'], ], '#attached' => [ 'library' => ['commerce_order/drupal.commerce_order'], ], '#weight' => 91, '#optional' => TRUE, ]; if (isset($form['uid'])) { $form['uid']['#group'] = 'author'; } if (isset($form['mail'])) { $form['mail']['#group'] = 'author'; } if (isset($form['created'])) { $form['created']['#group'] = 'author'; } return $form; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $reservation = $this->entity; $season_storage = $this->entityManager->getStorage('season'); $season = $season_storage->load($reservation->bundle()); $form['season'] = array('#type' => 'value', '#value' => $season->id()); return parent::form($form, $form_state); }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { $actions = parent::actions($form, $form_state); $actions['submit']['#value'] = $this->entity->book['original_bid'] ? $this->t('Update book outline') : $this->t('Add to book outline'); $actions['delete']['#value'] = $this->t('Remove from book outline'); $actions['delete']['#access'] = $this->bookManager->checkNodeIsRemovable($this->entity); return $actions; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { /* @var $entity \Drupal\content_entity_example\Entity\Contact */ $form = parent::buildForm($form, $form_state); $entity = $this->entity; $form['langcode'] = array('#title' => $this->t('Language'), '#type' => 'language_select', '#default_value' => $entity->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL); return $form; }
/** * {@inheritdoc} */ protected function actions(array $form, array &$form_state) { $actions = parent::actions($form, $form_state); $actions['submit']['#value'] = $this->getConfirmText(); unset($actions['delete']); // Prepare cancel link. $actions['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest()); return $actions; }
/** * {@inheritdoc} * * Always create a new revision */ public function submitForm(array &$form, FormStateInterface $form_state) { // Build the node object from the submitted values. parent::submitForm($form, $form_state); // Set new revision if needed if ($this->entity->id()) { $this->setNewRevision($form_state); } }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state, GroupInterface $group = NULL) { $group = $this->entity; if (!$group->isNew()) { $form['#title'] = $this->t('Edit group %label', array('%label' => $group->label())); } $form = parent::form($form, $form_state, $group); return $form; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { /** @var \Drupal\contact\MessageInterface $message */ $message = $this->entity; $form = parent::form($form, $form_state, $message); $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Author name'), '#maxlength' => 255, '#default_value' => $message->getSenderName()); $form['mail'] = array('#type' => 'email', '#title' => $this->t('Sender email address'), '#default_value' => $message->getSenderMail()); return $form; }
/** * {@inheritdoc} */ public function buildEntity(array $form, FormStateInterface $form_state) { $term = parent::buildEntity($form, $form_state); // Prevent leading and trailing spaces in term names. $term->setName(trim($term->getName())); // Assign parents with proper delta values starting from 0. $term->parent = array_keys($form_state->getValue('parent')); return $term; }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $entity = $this->entity; // @todo: Is there a better way to check if an entity type is revisionable? if ($entity->getEntityType()->hasKey('revision') && !$entity->isNew()) { $form['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $entity->isNewRevision()); } return $form; }
/** * Overrides \Drupal\Core\Entity\EntityForm::submit(). */ public function submit(array $form, array &$form_state) { // Build the entity object from the submitted values. $entity = parent::submit($form, $form_state); // Save as a new revision if requested to do so. if (!empty($form_state['values']['revision'])) { $entity->setNewRevision(); } return $entity; }
public function save(array $form, FormStateInterface $form_state) { /** @var FillPdfFormInterface $entity */ $entity = $this->entity; $form_state->setRedirect('entity.fillpdf_form.edit_form', [ 'fillpdf_form' => $this->entity->fillpdf_form->target_id, ]); return parent::save($form, $form_state); }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $entity = $this->entity; $form['langcode'] = array('#title' => t('Language'), '#type' => 'language_select', '#default_value' => $entity->getUntranslated()->language()->getId(), '#languages' => LanguageInterface::STATE_ALL); // @todo: Is there a better way to check if an entity type is revisionable? if ($entity->getEntityType()->hasKey('revision') && !$entity->isNew()) { $form['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $entity->isNewRevision()); } return $form; }
/** * {@inheritdoc} */ protected function flagViolations(EntityConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) { // Manually flag violations of fields not handled by the form display. This // is necessary as entity form displays only flag violations for fields // contained in the display. $field_names = array('label', 'machine_name'); foreach ($violations->getByFields($field_names) as $violation) { list($field_name) = explode('.', $violation->getPropertyPath(), 2); $form_state->setErrorByName($field_name, $violation->getMessage()); } parent::flagViolations($violations, $form, $form_state); }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form['advanced'] = array( '#type' => 'vertical_tabs', '#attributes' => array('class' => array('entity-meta')), '#weight' => 99, ); $form = parent::form($form, $form_state); $form['payment_status'] = array( '#type' => 'details', '#title' => t('Payment status'), '#group' => 'advanced', '#attributes' => array( 'class' => array('order-form-order-status'), ), '#attached' => array( 'library' => array('commerce_order/drupal.commerce_order'), ), '#weight' => 90, '#optional' => TRUE, ); if (isset($form['status'])) { $form['status']['#group'] = 'payment_status'; } // Payment info authoring information for administrators. $form['author'] = array( '#type' => 'details', '#title' => t('Authoring information'), '#group' => 'advanced', '#attributes' => array( 'class' => array('order-form-author'), ), '#attached' => array( 'library' => array('commerce_order/drupal.commerce_order'), ), '#weight' => 91, '#optional' => TRUE, ); if (isset($form['uid'])) { $form['uid']['#group'] = 'author'; } if (isset($form['created'])) { $form['created']['#group'] = 'author'; } return $form; }
/** * Overrides Drupal\Core\Entity\EntityFormController::form(). */ public function form(array $form, FormStateInterface $form_state) { /* @var $entity \Drupal\commerce_store\Entity\Store */ $form = parent::form($form, $form_state); $entity = $this->entity; $default_store = $this->storage->loadDefault(); $isDefault = TRUE; if ($default_store && $default_store->uuid() != $entity->uuid()) { $isDefault = FALSE; } $form['default'] = ['#type' => 'checkbox', '#title' => $this->t('Default'), '#default_value' => $isDefault, '#disabled' => $isDefault || empty($default_store), '#weight' => 99]; return $form; }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $entity = $this->entity; $status = parent::save($form, $form_state); switch ($status) { case SAVED_NEW: drupal_set_message($this->t('Created the %label Component.', ['%label' => $entity->label()])); break; default: drupal_set_message($this->t('Saved the %label Component.', ['%label' => $entity->label()])); } $form_state->setRedirect('entity.component.canonical', ['component' => $entity->id()]); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $form['#title'] = $this->getQuestion(); $form['#attributes']['class'][] = 'confirmation'; $form['description'] = array('#markup' => $this->getDescription()); $form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1); // By default, render the form using theme_confirm_form(). if (!isset($form['#theme'])) { $form['#theme'] = 'confirm_form'; } return $form; }
/** * Overrides Drupal\Core\Entity\EntityForm::actions(). */ protected function actions(array $form, FormStateInterface $form_state) { $element = parent::actions($form, $form_state); $profile = $this->entity; if (\Drupal::currentUser()->hasPermission('administer profiles')) { // Add an "Activate" button. $element['activate'] = $element['submit']; $element['activate']['#dropbutton'] = 'save'; if ($profile->isNew()) { $element['activate']['#value'] = t('Save and make active'); } else { $element['activate']['#value'] = $profile->isActive() ? t('Save and keep active') : t('Save and make active'); } $element['activate']['#weight'] = 0; array_unshift($element['activate']['#submit'], [$this, 'activate']); // Add a "Deactivate" button. $element['deactivate'] = $element['submit']; $element['deactivate']['#dropbutton'] = 'save'; if ($profile->isNew()) { $element['deactivate']['#value'] = t('Save as inactive'); } else { $element['deactivate']['#value'] = !$profile->isActive() ? t('Save and keep inactive') : t('Save and make inactive'); } $element['deactivate']['#weight'] = 10; array_unshift($element['deactivate']['#submit'], [ $this, 'deactivate' ]); // If already deactivated, the 'activate' button is primary. if ($profile->isActive()) { unset($element['deactivate']['#button_type']); } // Otherwise, the 'deactivate' button is primary and should come first. else { unset($element['deactivate']['#button_type']); $element['deactivate']['#weight'] = -10; } // Remove the "Save" button. $element['submit']['#access'] = FALSE; } $element['delete']['#access'] = $profile->access('delete'); $element['delete']['#weight'] = 100; return $element; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { /* @var $entity \Drupal\scheduled_updates\Entity\ScheduledUpdate */ $form = parent::buildForm($form, $form_state); $entity = $this->entity; $form['langcode'] = array( '#title' => $this->t('Language'), '#type' => 'language_select', '#default_value' => $entity->langcode->value, '#languages' => Language::STATE_ALL, ); return $form; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); $order = $this->entity; $original = clone $order; // Build list of changes to be applied. $panes = _uc_order_pane_list(); foreach ($panes as $pane) { if (in_array('edit', $pane['show'])) { $pane['callback']('edit-process', $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); } } } if (\Drupal::moduleHandler()->moduleExists('uc_stock')) { $qtys = array(); foreach ($order->products as $product) { $qtys[$product->order_product_id] = $product->qty; } } if (is_array($form_state->getValue('products'))) { foreach ($form_state->getValue('products') as $product) { if (!isset($product['remove']) && intval($product['qty']) > 0) { foreach (array('qty', 'title', 'model', 'weight', 'weight_units', 'cost', 'price') as $field) { $order->products[$product['order_product_id']]->{$field} = $product[$field]; } if (\Drupal::moduleHandler()->moduleExists('uc_stock')) { $product = (object) $product; $temp = $product->qty; $product->qty = $product->qty - $qtys[$product->order_product_id]; uc_stock_adjust_product_stock($product, 0, $order); $product->qty = $temp; } } else { $log['remove_' . $product['nid']] = $product['title'] . ' removed from order.'; } } } // 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(t('Order changes saved.')); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); /** @var \Drupal\user\Entity\User $assignee */ $assignee = User::load($form_state->getValue('tuid')); /** @var \Drupal\tmgmt_local\LocalTaskInterface $task */ $task = $this->getEntity(); $task->assign($assignee); $task->save(); drupal_set_message(t('Assigned @label to user @assignee_name.', array('@label' => $task->label(), '@assignee_name' => $assignee->getAccountName()))); $view = Views::getView('tmgmt_local_task_overview'); $view->initDisplay(); $form_state->setRedirect($view->getUrl()->getRouteName()); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { /* @var $entity \Drupal\myeck\Entity\Myeck */ $form = parent::buildForm($form, $form_state); //сделать универсальное для всех !!!!!!!!!!!!!!! // $entity = $this->entity; // $form['langcode'] = array( // '#title' => $this->t('Language'), // '#type' => 'language_select', // '#default_value' => $entity->getUntranslated()->language()->getId(), // '#languages' => Language::STATE_ALL, // ); return $form; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // Build the media object from the submitted values. parent::submitForm($form, $form_state); $media = $this->entity; // Save as a new revision if requested to do so. if (!$form_state->isValueEmpty('revision') && $form_state->getValue('revision') != FALSE) { $media->setNewRevision(); // If a new revision is created, save the current user as revision author. $media->set('revision_timestamp', REQUEST_TIME); $media->set('revision_uid', $this->currentUser()->id()); } else { $media->setNewRevision(FALSE); } }