/** * @covers ::normalize */ public function testNormalizeWithNoEntity() { $entity_reference = $this->prophesize(TypedDataInterface::class); $entity_reference->getValue()->willReturn(NULL)->shouldBeCalled(); $this->fieldItem->get('entity')->willReturn($entity_reference->reveal())->shouldBeCalled(); $normalized = $this->normalizer->normalize($this->fieldItem->reveal()); $expected = ['target_id' => ['value' => 'test']]; $this->assertSame($expected, $normalized); }
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties = parent::propertyDefinitions($field_definition); $properties[';value'] = DataDefinition::create('datetime_iso8601')->setLabel(t('Date value'))->setRequired(TRUE); $properties['date'] = DataDefinition::create('any')->setLabel(t('Computed date'))->setDescription(t('The computed DateTime object.'))->setComputed(TRUE)->setClass('\\Drupal\\datetime\\DateTimeComputed')->setSetting('date source', 'value'); return $properties; }
/** * {@inheritdoc} */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties = parent::propertyDefinitions($field_definition); $properties['display'] = DataDefinition::create('boolean')->setLabel(t('Display'))->setDescription(t('Flag to control whether this file should be displayed when viewing content')); $properties['description'] = DataDefinition::create('string')->setLabel(t('Description')); return $properties; }
/** * {@inheritdoc} */ public static function schema(FieldStorageDefinitionInterface $field_definition) { $schema = parent::schema($field_definition); $schema['columns']['status'] = array('description' => 'A flag indicating whether the user is subscribed (1) or unsubscribed (0).', 'type' => 'int', 'size' => 'tiny', 'not null' => FALSE); $schema['columns']['timestamp'] = array('description' => 'UNIX timestamp of when the user is (un)subscribed.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE); $schema['columns']['source'] = array('description' => 'The source via which the user is (un)subscription.', 'type' => 'varchar', 'length' => 24, 'not null' => FALSE); return $schema; }
/** * {@inheritdoc} */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties = parent::propertyDefinitions($field_definition); $properties['imported'] = DataDefinition::create('timestamp')->setLabel(t('Timestamp')); $properties['url'] = DataDefinition::create('uri')->setLabel(t('Item URL')); $properties['guid'] = DataDefinition::create('string')->setLabel(t('Item GUID')); $properties['hash'] = DataDefinition::create('string')->setLabel(t('Item hash')); return $properties; }
/** * {@inheritdoc} */ public function getConstraints() { $constraints = parent::getConstraints(); // Remove the 'AllowedValuesConstraint' validation constraint because entity // reference fields already use the 'ValidReference' constraint. foreach ($constraints as $key => $constraint) { if ($constraint instanceof AllowedValuesConstraint) { unset($constraints[$key]); } } return $constraints; }
public function setValue($values, $notify = TRUE) { if (count($values) == 1 && isset($values['target_id'])) { $values = array_merge($this->values, $values); if (!isset($values['handler']) || $values['handler'] == NULL) { $values['handler'] = 'simplenews_all'; } if (!isset($values['status']) || $values['status'] == NULL) { $values['status'] = 0; } if (!isset($values['sent_count']) || $values['sent_count'] == NULL) { $values['sent_count'] = 0; } if (!isset($values['subscribers']) || $values['subscribers'] == NULL) { $values['subscribers'] = 0; } } parent::setValue($values, $notify); // TODO: Change the autogenerated stub }
/** * Returns whether the entity referenced by an item needs to be loaded. * * @param \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $item * The item to check. * * @return bool * TRUE if the entity needs to be loaded. */ protected function needsEntityLoad(EntityReferenceItem $item) { return !$item->hasNewEntity(); }
/** * {@inheritdoc} */ public static function defaultSettings() { return array('target_type' => 'taxonomy_term', 'options_list_callback' => NULL, 'allowed_values' => array(array('vocabulary' => '', 'parent' => 0))) + parent::defaultSettings(); }
/** * {@inheritdoc} */ public function delete() { parent::delete(); if ($this->entity && $this->entity->getEntityType()->get('entity_revision_parent_type_field') && $this->entity->getEntityType()->get('entity_revision_parent_id_field')) { $this->entity->delete(); } }
/** * Helper method to mock all store definitions. */ protected function setupFieldStorageDefinition() { $id_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'); $id_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(IntegerItem::schema($id_field_storage_definition)); $uuid_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'); $uuid_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(UuidItem::schema($uuid_field_storage_definition)); $type_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'); $type_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(StringItem::schema($type_field_storage_definition)); $langcode_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'); $langcode_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(LanguageItem::schema($langcode_field_storage_definition)); $name_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'); $name_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(StringItem::schema($name_field_storage_definition)); $description_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'); $description_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(TextLongItem::schema($description_field_storage_definition)); $homepage_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'); $homepage_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(UriItem::schema($homepage_field_storage_definition)); // Setup the user_id entity reference field. $this->entityManager->expects($this->any())->method('getDefinition')->willReturnMap([['user', TRUE, static::userEntityInfo()]]); $user_id_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'); $user_id_field_storage_definition->expects($this->any())->method('getSetting')->with('target_type')->willReturn('user'); $user_id_field_storage_definition->expects($this->any())->method('getSettings')->willReturn(['target_type' => 'user']); $user_id_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(EntityReferenceItem::schema($user_id_field_storage_definition)); $revision_id_field_storage_definition = $this->getMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'); $revision_id_field_storage_definition->expects($this->any())->method('getSchema')->willReturn(IntegerItem::schema($revision_id_field_storage_definition)); $this->entityManager->expects($this->any())->method('getFieldStorageDefinitions')->willReturn(['id' => $id_field_storage_definition, 'uuid' => $uuid_field_storage_definition, 'type' => $type_field_storage_definition, 'langcode' => $langcode_field_storage_definition, 'name' => $name_field_storage_definition, 'description' => $description_field_storage_definition, 'homepage' => $homepage_field_storage_definition, 'user_id' => $user_id_field_storage_definition, 'revision_id' => $revision_id_field_storage_definition]); }
/** * {@inheritdoc} */ public function preSave() { parent::preSave(); $this->target_revision_id = $this->entity->getRevisionId(); }
/** * {@inheritdoc} */ public static function defaultFieldSettings() { return array('handler' => 'default:taxonomy_term') + parent::defaultFieldSettings(); }
/** * {@inheritdoc} */ public function isEmpty() { return parent::isEmpty(); }
/** * {@inheritdoc} */ public static function schema(FieldStorageDefinitionInterface $field_definition) { $schema = parent::schema($field_definition); $target_type = $field_definition->getSetting('target_type'); $target_type_info = \Drupal::entityManager()->getDefinition($target_type); if ($target_type_info->isSubclassOf('\\Drupal\\Core\\Entity\\ContentEntityInterface') && $field_definition instanceof FieldStorageConfigInterface) { $schema['columns']['revision_id'] = array('description' => 'The revision ID of the target entity.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE); } return $schema; }
/** * {@inheritdoc} */ public static function defaultStorageSettings() { return array('target_type' => 'field_collection_item') + parent::defaultStorageSettings(); }