Chris@0: get('title')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { Chris@0: /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */ Chris@0: $fields = parent::baseFieldDefinitions($entity_type); Chris@0: Chris@0: $fields['iid']->setLabel(t('Aggregator item ID')) Chris@0: ->setDescription(t('The ID of the feed item.')); Chris@0: Chris@0: $fields['langcode']->setLabel(t('Language code')) Chris@0: ->setDescription(t('The feed item language code.')); Chris@0: Chris@0: $fields['fid'] = BaseFieldDefinition::create('entity_reference') Chris@0: ->setLabel(t('Source feed')) Chris@0: ->setRequired(TRUE) Chris@0: ->setDescription(t('The aggregator feed entity associated with this item.')) Chris@0: ->setSetting('target_type', 'aggregator_feed') Chris@0: ->setDisplayOptions('view', [ Chris@0: 'label' => 'hidden', Chris@0: 'type' => 'entity_reference_label', Chris@0: 'weight' => 0, Chris@0: ]) Chris@0: ->setDisplayConfigurable('form', TRUE); Chris@0: Chris@0: $fields['title'] = BaseFieldDefinition::create('string') Chris@0: ->setLabel(t('Title')) Chris@0: ->setDescription(t('The title of the feed item.')); Chris@0: Chris@0: $fields['link'] = BaseFieldDefinition::create('uri') Chris@0: ->setLabel(t('Link')) Chris@0: ->setDescription(t('The link of the feed item.')) Chris@0: ->setDisplayOptions('view', [ Chris@0: 'region' => 'hidden', Chris@0: ]) Chris@0: ->setDisplayConfigurable('view', TRUE); Chris@0: Chris@0: $fields['author'] = BaseFieldDefinition::create('string') Chris@0: ->setLabel(t('Author')) Chris@0: ->setDescription(t('The author of the feed item.')) Chris@0: ->setDisplayOptions('view', [ Chris@0: 'label' => 'hidden', Chris@0: 'weight' => 3, Chris@0: ]) Chris@0: ->setDisplayConfigurable('view', TRUE); Chris@0: Chris@0: $fields['description'] = BaseFieldDefinition::create('string_long') Chris@0: ->setLabel(t('Description')) Chris@0: ->setDescription(t('The body of the feed item.')); Chris@0: Chris@0: $fields['timestamp'] = BaseFieldDefinition::create('created') Chris@0: ->setLabel(t('Posted on')) Chris@0: ->setDescription(t('Posted date of the feed item, as a Unix timestamp.')) Chris@0: ->setDisplayOptions('view', [ Chris@0: 'label' => 'hidden', Chris@0: 'type' => 'timestamp_ago', Chris@0: 'weight' => 1, Chris@0: ]) Chris@0: ->setDisplayConfigurable('view', TRUE); Chris@0: Chris@0: // @todo Convert to a real UUID field in Chris@0: // https://www.drupal.org/node/2149851. Chris@0: $fields['guid'] = BaseFieldDefinition::create('string_long') Chris@0: ->setLabel(t('GUID')) Chris@0: ->setDescription(t('Unique identifier for the feed item.')); Chris@0: Chris@0: return $fields; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getFeedId() { Chris@0: return $this->get('fid')->target_id; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setFeedId($fid) { Chris@0: return $this->set('fid', $fid); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getTitle() { Chris@0: return $this->get('title')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setTitle($title) { Chris@0: return $this->set('title', $title); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getLink() { Chris@0: return $this->get('link')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setLink($link) { Chris@0: return $this->set('link', $link); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getAuthor() { Chris@0: return $this->get('author')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setAuthor($author) { Chris@0: return $this->set('author', $author); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getDescription() { Chris@0: return $this->get('description')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setDescription($description) { Chris@0: return $this->set('description', $description); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getPostedTime() { Chris@0: return $this->get('timestamp')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setPostedTime($timestamp) { Chris@0: return $this->set('timestamp', $timestamp); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getGuid() { Chris@0: return $this->get('guid')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setGuid($guid) { Chris@0: return $this->set('guid', $guid); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function postSave(EntityStorageInterface $storage, $update = TRUE) { Chris@0: parent::postSave($storage, $update); Chris@0: Chris@0: // Entity::postSave() calls Entity::invalidateTagsOnSave(), which only Chris@0: // handles the regular cases. The Item entity has one special case: a newly Chris@0: // created Item is *also* associated with a Feed, so we must invalidate the Chris@0: // associated Feed's cache tag. Chris@0: if (!$update) { Chris@0: Cache::invalidateTags($this->getCacheTagsToInvalidate()); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getCacheTagsToInvalidate() { Chris@0: return Feed::load($this->getFeedId())->getCacheTags(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Entity URI callback. Chris@0: */ Chris@0: public static function buildUri(ItemInterface $item) { Chris@0: return Url::fromUri($item->getLink()); Chris@0: } Chris@0: Chris@0: }