diff --git a/core/modules/aggregator/aggregator.install b/core/modules/aggregator/aggregator.install index ad5f92f1fb94227f76ab4b39c870ac4a70b2dcf5..a763639f8880758712a0e62fbc7302a6556ff701 100644 --- a/core/modules/aggregator/aggregator.install +++ b/core/modules/aggregator/aggregator.install @@ -21,3 +21,19 @@ function aggregator_requirements($phase) { } return $requirements; } + +/** + * @addtogroup updates-8.0.0-rc + * @{ + */ + +/** + * The simple presence of this update function clears cached field definitions. + */ +function aggregator_update_8001() { + // Feed ID base field is now required. +} + +/** + * @} End of "addtogroup updates-8.0.0-rc". + */ diff --git a/core/modules/aggregator/src/Entity/Item.php b/core/modules/aggregator/src/Entity/Item.php index f175d3a9a474469fe8c90f082b192e1348a84a57..4c6d10464d9ec3f1d052191ce847a13610b5b267 100644 --- a/core/modules/aggregator/src/Entity/Item.php +++ b/core/modules/aggregator/src/Entity/Item.php @@ -60,6 +60,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['fid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Source feed')) + ->setRequired(TRUE) ->setDescription(t('The aggregator feed entity associated with this item.')) ->setSetting('target_type', 'aggregator_feed') ->setDisplayOptions('view', array( diff --git a/core/modules/aggregator/src/Tests/ItemWithoutFeedTest.php b/core/modules/aggregator/src/Tests/ItemWithoutFeedTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a6586b934d01c7f8a2e604815364c0f851aef75b --- /dev/null +++ b/core/modules/aggregator/src/Tests/ItemWithoutFeedTest.php @@ -0,0 +1,46 @@ +<?php + +/** + * @file + * Contains \Drupal\aggregator\Tests\ItemWithoutFeedTest. + */ + +namespace Drupal\aggregator\Tests; + +use Drupal\aggregator\Entity\Item; +use Drupal\KernelTests\KernelTestBase; + +/** + * Tests clean handling of an item with a missing feed ID. + * + * @group aggregator + */ +class ItemWithoutFeedTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['aggregator', 'options']; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('aggregator_feed'); + $this->installEntitySchema('aggregator_item'); + } + + /** + * Tests attempting to create a feed item without a feed. + */ + public function testEntityCreation() { + $entity = Item::create([ + 'title' => t('Llama 2'), + 'path' => 'https://groups.drupal.org/', + ]); + $violations = $entity->validate(); + $this->assertCount(1, $violations); + } + +}