/**
  * Executes a test set for a defined entity type.
  *
  * @param string $entity_type
  *   The entity type to run the tests with.
  */
 protected function assertDefaultValues($entity_type)
 {
     $entity = entity_create($entity_type);
     $this->assertEqual($entity->langcode->value, 'en', String::format('%entity_type: Default language', array('%entity_type' => $entity_type)));
     $this->assertTrue(Uuid::isValid($entity->uuid->value), String::format('%entity_type: Default UUID', array('%entity_type' => $entity_type)));
     $this->assertEqual($entity->name->getValue(), array(0 => array('value' => NULL)), 'Field has one empty value by default.');
 }
 /**
  * Executes a test set for a defined entity type.
  *
  * @param string $entity_type_id
  *   The entity type to run the tests with.
  */
 protected function assertDefaultValues($entity_type_id)
 {
     $entity = entity_create($entity_type_id);
     $definition = $this->entityManager->getDefinition($entity_type_id);
     $langcode_key = $definition->getKey('langcode');
     $this->assertEqual($entity->{$langcode_key}->value, 'en', SafeMarkup::format('%entity_type: Default language', array('%entity_type' => $entity_type_id)));
     $this->assertTrue(Uuid::isValid($entity->uuid->value), SafeMarkup::format('%entity_type: Default UUID', array('%entity_type' => $entity_type_id)));
     $this->assertEqual($entity->name->getValue(), array(), 'Field has one empty value by default.');
 }
 public function get($uuid = NULL)
 {
     if (Uuid::isValid($uuid)) {
         $entity = $this->getArticle($uuid);
         return new ResourceResponse($this->transform($entity));
     } else {
         return new ResourceResponse(['http_code' => 400, 'error' => 100, 'message' => 'The UUID supplied is invalid.'], 400);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $condition = NULL, $tempstore_id = NULL, $machine_name = NULL)
 {
     $this->tempstore_id = $tempstore_id;
     $this->machine_name = $machine_name;
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     if (is_numeric($condition) || Uuid::isValid($condition)) {
         $id = $condition;
         $condition = $this->getConditions($cached_values)[$id];
         $instance = $this->manager->createInstance($condition['id'], $condition);
     } else {
         $instance = $this->manager->createInstance($condition, []);
     }
     $form_state->setTemporaryValue('gathered_contexts', $this->getContexts($cached_values));
     /** @var $instance \Drupal\Core\Condition\ConditionInterface */
     $form = $instance->buildConfigurationForm($form, $form_state);
     if (isset($id)) {
         // Conditionally set this form element so that we can update or add.
         $form['id'] = ['#type' => 'value', '#value' => $id];
     }
     $form['instance'] = ['#type' => 'value', '#value' => $instance];
     $form['submit'] = ['#type' => 'submit', '#value' => $this->t('Save'), '#ajax' => ['callback' => [$this, 'ajaxSave']]];
     return $form;
 }
 /**
  * Tests UUID validation.
  *
  * @param string $uuid
  *   The uuid to check against.
  * @param bool $is_valid
  *   Whether the uuid is valid or not.
  * @param string $message
  *   The message to display on failure.
  *
  * @dataProvider providerTestValidation
  */
 public function testValidation($uuid, $is_valid, $message)
 {
     $this->assertSame($is_valid, Uuid::isValid($uuid), $message);
 }