/**
  * Runs basic tests for node_last_changed function.
  */
 function testNodeLastChanged()
 {
     $node = entity_create('node', array('type' => 'article', 'title' => $this->randomMachineName()));
     $node->save();
     // Test node last changed timestamp.
     $changed_timestamp = node_last_changed($node->id());
     $this->assertEqual($changed_timestamp, $node->getChangedTime(), 'Expected last changed timestamp returned.');
     $changed_timestamp = node_last_changed($node->id(), $node->language()->getId());
     $this->assertEqual($changed_timestamp, $node->getChangedTime(), 'Expected last changed timestamp returned.');
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $node = $this->buildEntity($form, $form_state);
     if ($node->id() && node_last_changed($node->id(), $this->getFormLangcode($form_state)) > $node->getChangedTime()) {
         $form_state->setErrorByName('changed', $this->t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));
     }
     // Invoke hook_node_validate() for validation needed by modules.
     // Can't use \Drupal::moduleHandler()->invokeAll(), because $form_state must
     // be receivable by reference.
     foreach (\Drupal::moduleHandler()->getImplementations('node_validate') as $module) {
         $function = $module . '_node_validate';
         $function($node, $form, $form_state);
     }
     parent::validate($form, $form_state);
 }
예제 #3
0
파일: Node.php 프로젝트: ab-k/phresco
 function testLastChanged()
 {
     $this->connect();
     $changed = node_last_changed(1);
     $this->assertEquals('1330420018', $changed);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $node = parent::validate($form, $form_state);
     if ($node->id() && node_last_changed($node->id()) > $node->getChangedTimeAcrossTranslations()) {
         $form_state->setErrorByName('changed', $this->t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));
     }
     return $node;
 }
예제 #5
0
 /**
  * Overrides Drupal\Core\Entity\EntityForm::validate().
  */
 public function validate(array $form, array &$form_state)
 {
     $node = $this->buildEntity($form, $form_state);
     if ($node->id() && node_last_changed($node->id(), $this->getFormLangcode($form_state)) > $node->getChangedTime()) {
         $this->setFormError('changed', $form_state, $this->t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));
     }
     // Validate the "authored by" field.
     if (!empty($form_state['values']['uid']) && !user_load_by_name($form_state['values']['uid'])) {
         // The use of empty() is mandatory in the context of usernames
         // as the empty string denotes the anonymous user. In case we
         // are dealing with an anonymous user we set the user ID to 0.
         $this->setFormError('uid', $form_state, $this->t('The username %name does not exist.', array('%name' => $form_state['values']['uid'])));
     }
     // Validate the "authored on" field.
     // The date element contains the date object.
     $date = $node->date instanceof DrupalDateTime ? $node->date : new DrupalDateTime($node->date);
     if ($date->hasErrors()) {
         $this->setFormError('date', $form_state, $this->t('You have to specify a valid date.'));
     }
     // Invoke hook_node_validate() for validation needed by modules.
     // Can't use \Drupal::moduleHandler()->invokeAll(), because $form_state must
     // be receivable by reference.
     foreach (\Drupal::moduleHandler()->getImplementations('node_validate') as $module) {
         $function = $module . '_node_validate';
         $function($node, $form, $form_state);
     }
     parent::validate($form, $form_state);
 }