/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL) { $form['#title'] = $this->t('<em>Edit @type stock</em> @title', ['@type' => node_get_type_label($node), '@title' => $node->label()]); $form['stock'] = array('#type' => 'table', '#header' => array(array('data' => ' ' . $this->t('Active'), 'class' => array('select-all', 'nowrap')), $this->t('SKU'), $this->t('Stock'), $this->t('Threshold'))); $form['#attached']['library'][] = 'core/drupal.tableselect'; $skus = uc_product_get_models($node->id(), FALSE); foreach ($skus as $sku) { $stock = db_query("SELECT * FROM {uc_product_stock} WHERE sku = :sku", [':sku' => $sku])->fetchAssoc(); $form['stock'][$sku]['active'] = array('#type' => 'checkbox', '#default_value' => !empty($stock['active']) ? $stock['active'] : 0); $form['stock'][$sku]['sku'] = array('#markup' => $sku); $form['stock'][$sku]['stock'] = array('#type' => 'textfield', '#default_value' => !empty($stock['stock']) ? $stock['stock'] : 0, '#maxlength' => 9, '#size' => 9); $form['stock'][$sku]['threshold'] = array('#type' => 'textfield', '#default_value' => !empty($stock['threshold']) ? $stock['threshold'] : 0, '#maxlength' => 9, '#size' => 9); } $form['nid'] = array('#type' => 'value', '#value' => $node->id()); $form['actions'] = array('#type' => 'actions'); $form['actions']['save'] = array('#type' => 'submit', '#value' => $this->t('Save changes')); return $form; }
/** * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { /** @var \Drupal\node\NodeInterface $entity */ $mark = array('#theme' => 'mark', '#mark_type' => node_mark($entity->id(), $entity->getChangedTime())); $langcode = $entity->language()->getId(); $uri = $entity->urlInfo(); $options = $uri->getOptions(); $options += $langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array(); $uri->setOptions($options); $row['title']['data'] = array('#type' => 'link', '#title' => $entity->label(), '#suffix' => ' ' . drupal_render($mark), '#url' => $uri); $row['type'] = node_get_type_label($entity); $row['author']['data'] = array('#theme' => 'username', '#account' => $entity->getOwner()); $row['status'] = $entity->isPublished() ? $this->t('published') : $this->t('not published'); $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short'); $language_manager = \Drupal::languageManager(); if ($language_manager->isMultilingual()) { $row['language_name'] = $language_manager->getLanguageName($langcode); } $row['operations']['data'] = $this->buildOperations($entity); return $row + parent::buildRow($entity); }
/** * {@inheritdoc} */ protected function entityFormTitle(EntityInterface $entity) { $type_name = node_get_type_label($entity); return t('<em>Edit @type</em> @title', array('@type' => $type_name, '@title' => $entity->label())); }
/** * Prepares a message based on parameters; * * This hook is called from MailManagerInterface->mail(). Note that hook_mail(), * unlike hook_mail_alter(), is only called on the $module argument to * MailManagerInterface->mail(), not all modules. * * @param $key * An identifier of the mail. * @param $message * An array to be filled in. Elements in this array include: * - id: An ID to identify the mail sent. Look at module source code or * MailManagerInterface->mail() for possible id values. * - to: The address or addresses the message will be sent to. The * formatting of this string must comply with RFC 2822. * - subject: Subject of the email to be sent. This must not contain any * newline characters, or the mail may not be sent properly. * MailManagerInterface->mail() sets this to an empty * string when the hook is invoked. * - body: An array of lines containing the message to be sent. Drupal will * format the correct line endings for you. MailManagerInterface->mail() * sets this to an empty array when the hook is invoked. The array may * contain either strings or objects implementing * \Drupal\Component\Render\MarkupInterface. * - from: The address the message will be marked as being from, which is * set by MailManagerInterface->mail() to either a custom address or the * site-wide default email address when the hook is invoked. * - headers: Associative array containing mail headers, such as From, * Sender, MIME-Version, Content-Type, etc. * MailManagerInterface->mail() pre-fills several headers in this array. * @param $params * An array of parameters supplied by the caller of * MailManagerInterface->mail(). * * @see \Drupal\Core\Mail\MailManagerInterface::mail() */ function hook_mail($key, &$message, $params) { $account = $params['account']; $context = $params['context']; $variables = array('%site_name' => \Drupal::config('system.site')->get('name'), '%username' => $account->getDisplayName()); if ($context['hook'] == 'taxonomy') { $entity = $params['entity']; $vocabulary = Vocabulary::load($entity->id()); $variables += array('%term_name' => $entity->name, '%term_description' => $entity->description, '%term_id' => $entity->id(), '%vocabulary_name' => $vocabulary->label(), '%vocabulary_description' => $vocabulary->getDescription(), '%vocabulary_id' => $vocabulary->id()); } // Node-based variable translation is only available if we have a node. if (isset($params['node'])) { /** @var \Drupal\node\NodeInterface $node */ $node = $params['node']; $variables += array('%uid' => $node->getOwnerId(), '%url' => $node->url('canonical', array('absolute' => TRUE)), '%node_type' => node_get_type_label($node), '%title' => $node->getTitle(), '%teaser' => $node->teaser, '%body' => $node->body); } $subject = strtr($context['subject'], $variables); $body = strtr($context['message'], $variables); $message['subject'] .= str_replace(array("\r", "\n"), '', $subject); $message['body'][] = MailFormatHelper::htmlToText($body); }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $node = $this->entity; $insert = $node->isNew(); $node->save(); $node_link = $node->link($this->t('View')); $context = array('@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link); $t_args = array('@type' => node_get_type_label($node), '%title' => $node->label()); if ($insert) { $this->logger('content')->notice('@type: added %title.', $context); drupal_set_message(t('@type %title has been created.', $t_args)); } else { $this->logger('content')->notice('@type: updated %title.', $context); drupal_set_message(t('@type %title has been updated.', $t_args)); } if ($node->id()) { $form_state->setValue('nid', $node->id()); $form_state->set('nid', $node->id()); if ($node->access('view')) { $form_state->setRedirect('entity.node.canonical', array('node' => $node->id())); } else { $form_state->setRedirect('<front>'); } // Remove the preview entry from the temp store, if any. $store = $this->tempStoreFactory->get('node_preview'); $store->delete($node->uuid()); } else { // In the unlikely case something went wrong on save, the node will be // rebuilt and node form redisplayed the same way as in preview. drupal_set_message(t('The post could not be saved.'), 'error'); $form_state->setRebuild(); } }
/** * {@inheritdoc} */ protected function doTestTranslationEdit() { $entity = entity_load($this->entityTypeId, $this->entityId, TRUE); $languages = $this->container->get('language_manager')->getLanguages(); $type_name = node_get_type_label($entity); foreach ($this->langcodes as $langcode) { // We only want to test the title for non-english translations. if ($langcode != 'en') { $options = array('language' => $languages[$langcode]); $url = $entity->urlInfo('edit-form', $options); $this->drupalGet($url); $title = t('<em>Edit @type</em> @title [%language translation]', array('@type' => $type_name, '@title' => $entity->getTranslation($langcode)->label(), '%language' => $languages[$langcode]->getName())); $this->assertRaw($title); } } }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // The revision timestamp will be updated when the revision is saved. Keep // the original one for the confirmation message. $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision = $this->prepareRevertedRevision($this->revision, $form_state); $this->revision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]); $this->revision->save(); $this->logger('content')->notice('@type: reverted %title revision %revision.', ['@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]); drupal_set_message(t('@type %title has been reverted to the revision from %revision-date.', ['@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)])); $form_state->setRedirect('entity.node.version_history', array('node' => $this->revision->id())); }
/** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { $this->revision->setNewRevision(); // Make this the new default revision for the node. $this->revision->isDefaultRevision(TRUE); // The revision timestamp will be updated when the revision is saved. Keep the // original one for the confirmation message. $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision->revision_log = t('Copy of the revision from %date.', array('%date' => format_date($original_revision_timestamp))); $this->revision->save(); watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId())); drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => format_date($original_revision_timestamp)))); $form_state['redirect_route'] = array('route_name' => 'node.revision_overview', 'route_parameters' => array('node' => $this->revision->id())); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->revision->setNewRevision(); // Make this the new default revision for the node. $this->revision->isDefaultRevision(TRUE); // The revision timestamp will be updated when the revision is saved. Keep the // original one for the confirmation message. $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision->revision_log = t('Copy of the revision from %date.', array('%date' => format_date($original_revision_timestamp))); $this->revision->save(); $this->logger('content')->notice('@type: reverted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId())); drupal_set_message(t('@type %title has been reverted to the revision from %revision-date.', array('@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => format_date($original_revision_timestamp)))); $form_state->setRedirect('entity.node.version_history', array('node' => $this->revision->id())); }
/** * Overrides Drupal\Core\Entity\EntityForm::save(). */ public function save(array $form, array &$form_state) { $node = $this->entity; $insert = $node->isNew(); $node->save(); $node_link = l(t('View'), 'node/' . $node->id()); $watchdog_args = array('@type' => $node->getType(), '%title' => $node->label()); $t_args = array('@type' => node_get_type_label($node), '%title' => $node->label()); if ($insert) { watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link); drupal_set_message(t('@type %title has been created.', $t_args)); } else { watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link); drupal_set_message(t('@type %title has been updated.', $t_args)); } if ($node->id()) { $form_state['values']['nid'] = $node->id(); $form_state['nid'] = $node->id(); if ($node->access('view')) { $form_state['redirect_route'] = array('route_name' => 'node.view', 'route_parameters' => array('node' => $node->id())); } else { $form_state['redirect_route']['route_name'] = '<front>'; } } else { // In the unlikely case something went wrong on save, the node will be // rebuilt and node form redisplayed the same way as in preview. drupal_set_message(t('The post could not be saved.'), 'error'); $form_state['rebuild'] = TRUE; } }
/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $node = $this->entity; $insert = $node->isNew(); $node->save(); $node_link = l(t('View'), 'node/' . $node->id()); $context = array('@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link); $t_args = array('@type' => node_get_type_label($node), '%title' => $node->label()); if ($insert) { $this->logger('content')->notice('@type: added %title.', $context); drupal_set_message(t('@type %title has been created.', $t_args)); } else { $this->logger('content')->notice('@type: updated %title.', $context); drupal_set_message(t('@type %title has been updated.', $t_args)); } if ($node->id()) { $form_state['values']['nid'] = $node->id(); $form_state['nid'] = $node->id(); if ($node->access('view')) { $form_state->setRedirect('node.view', array('node' => $node->id())); } else { $form_state->setRedirect('<front>'); } } else { // In the unlikely case something went wrong on save, the node will be // rebuilt and node form redisplayed the same way as in preview. drupal_set_message(t('The post could not be saved.'), 'error'); $form_state['rebuild'] = TRUE; } }