本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityForm::submitForm方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityForm::submitForm方法的具体用法?PHP ContentEntityForm::submitForm怎么用?PHP ContentEntityForm::submitForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\ContentEntityForm
的用法示例。
在下文中一共展示了ContentEntityForm::submitForm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: submitForm
/**
* {@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())));
}
}
示例2: submitForm
/**
* {@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);
}
}
示例3: submitForm
/**
* {@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());
}
示例4: submitForm
/**
* {@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.'));
}
示例5: submitForm
/**
* {@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);
}
}
示例6: submitForm
/**
* Overrides \Drupal\Core\Entity\EntityFormController::submit().
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Build the block object from the submitted values.
parent::submitForm($form, $form_state);
$field_collection_item = $this->entity;
// TODO: Create new revision every edit? Might be better to make it an
// option. In either case, it doesn't work as is. The default
// revision of the host isn't getting updated to point to the new
// field collection item revision.
// $field_collection_item->setNewRevision();
if (\Drupal::routeMatch()->getRouteName() == 'field_collection_item.add_page') {
$host = entity_load(\Drupal::routeMatch()->getParameter('host_type'), \Drupal::routeMatch()->getParameter('host_id'));
} else {
$host = $field_collection_item->getHost();
}
$form_state->setRedirect($host->urlInfo()->getRouteName(), $host->urlInfo()->getRouteParameters());
}
示例7: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
parent::submitForm($form, $form_state);
$user = $this->getEntity($form_state);
// If there's a session set to the users id, remove the password reset tag
// since a new password was saved.
if (isset($_SESSION['pass_reset_' . $user->id()])) {
unset($_SESSION['pass_reset_' . $user->id()]);
}
}
示例8: submitForm
/**
* {@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);
// If not a new entity, get the original
$original = NULL;
if ($this->entity->id()) {
$storage = \Drupal::entityManager()->getStorage('node');
$original = $storage->loadUnchanged($this->entity->id());
}
$this->addUserAsParticipant($original);
// Set new revision if needed
if ($this->entity->id()) {
$this->considerNewRevision($form_state, $original);
}
}
示例9: submitForm
/**
* {@inheritdoc}
*
* Updates the node object by processing the submitted values.
*
* This function can be called by a "Next" button of a wizard to update the
* form state's entity with the current step's values before proceeding to the
* next step.
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Build the node object from the submitted values.
parent::submitForm($form, $form_state);
$node = $this->entity;
// Save as a new revision if requested to do so.
if (!$form_state->isValueEmpty('revision') && $form_state->getValue('revision') != FALSE) {
$node->setNewRevision();
// If a new revision is created, save the current user as revision author.
$node->setRevisionCreationTime(REQUEST_TIME);
$node->setRevisionAuthorId(\Drupal::currentUser()->id());
} else {
$node->setNewRevision(FALSE);
}
}
示例10: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
parent::submitForm($form, $form_state);
/** @var \Drupal\comment\CommentInterface $comment */
$comment = $this->entity;
// If the comment was posted by a registered user, assign the author's ID.
// @todo Too fragile. Should be prepared and stored in comment_form()
// already.
$author_name = $comment->getAuthorName();
if (!$comment->is_anonymous && !empty($author_name) && ($account = user_load_by_name($author_name))) {
$comment->setOwner($account);
}
// If the comment was posted by an anonymous user and no author name was
// required, use "Anonymous" by default.
if ($comment->is_anonymous && (!isset($author_name) || $author_name === '')) {
$comment->setAuthorName($this->config('user.settings')->get('anonymous'));
}
// Validate the comment's subject. If not specified, extract from comment
// body.
if (trim($comment->getSubject()) == '') {
// The body may be in any format, so:
// 1) Filter it into HTML
// 2) Strip out all HTML tags
// 3) Convert entities back to plain-text.
$comment_text = $comment->comment_body->processed;
$comment->setSubject(Unicode::truncate(trim(String::decodeEntities(strip_tags($comment_text))), 29, TRUE));
// Edge cases where the comment body is populated only by HTML tags will
// require a default subject.
if ($comment->getSubject() == '') {
$comment->setSubject($this->t('(No subject)'));
}
}
return $comment;
}
示例11: submitConfigurationForm
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
{
// Remove button and internal Form API values from submitted values.
parent::submitForm($form, $form_state);
$this->save($form, $form_state);
}
示例12: submitForm
/**
* {@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.'));
}
示例13: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Subclasses try to load an existing subscriber in different ways in
// buildForm. For anonymous user the email is unknown in buildForm, but here
// we can try again to load an existing subscriber.
$mail = $form_state->getValue(array('mail', 0, 'value'));
if ($this->entity->isNew() && isset($mail) && ($subscriber = simplenews_subscriber_load_by_mail($mail))) {
$this->setEntity($subscriber);
}
parent::submitForm($form, $form_state);
}
示例14: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
parent::submitForm($form, $form_state);
$this->plugin->submitConfigurationForm($form, $form_state);
}
示例15: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
parent::submitForm($form, $form_state);
$line_item_type_storage = $this->entityManager->getStorage('commerce_line_item_type');
/** @var \Drupal\commerce_order\Entity\LineItemInterface $line_item */
$line_item = $this->entity;
/** @var \Drupal\commerce\PurchasableEntityInterface $purchased_entity */
$purchased_entity = $line_item->getPurchasedEntity();
/** @var \Drupal\commerce_order\Entity\LineItemTypeInterface $line_item_type */
$line_item_type = $line_item_type_storage->load($line_item->bundle());
$store = $this->selectStore($purchased_entity);
$cart = $this->cartProvider->getCart($line_item_type->getOrderTypeId(), $store);
if (!$cart) {
$cart = $this->cartProvider->createCart('default', $store);
}
$this->cartManager->addLineItem($cart, $line_item, $form_state->get(['settings', 'combine']));
drupal_set_message(t('@entity added to @cart-link.', ['@entity' => $purchased_entity->label(), '@cart-link' => Link::createFromRoute('your cart', 'commerce_cart.page')->toString()]));
}