Item.php 4.4 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Contains \Drupal\aggregator\Entity\Item.
6
7
 */

8
namespace Drupal\aggregator\Entity;
9

10
use Drupal\Core\Entity\ContentEntityBase;
11
use Drupal\Core\Entity\EntityStorageInterface;
12
use Drupal\aggregator\ItemInterface;
13
use Drupal\Core\Entity\EntityTypeInterface;
14
use Drupal\Core\Field\FieldDefinition;
15
16
17
18

/**
 * Defines the aggregator item entity class.
 *
19
 * @ContentEntityType(
20
21
 *   id = "aggregator_item",
 *   label = @Translation("Aggregator feed item"),
22
 *   controllers = {
23
 *     "storage" = "Drupal\aggregator\ItemStorage",
24
 *     "view_builder" = "Drupal\aggregator\ItemViewBuilder"
25
 *   },
26
27
28
29
30
31
32
33
 *   base_table = "aggregator_item",
 *   fieldable = TRUE,
 *   entity_keys = {
 *     "id" = "iid",
 *     "label" = "title",
 *   }
 * )
 */
34
class Item extends ContentEntityBase implements ItemInterface {
35
36
37
38
39
40
41
42
43
44
45

  /**
   * Implements Drupal\Core\Entity\EntityInterface::id().
   */
  public function id() {
    return $this->get('iid')->value;
  }

  /**
   * Implements Drupal\Core\Entity\EntityInterface::label().
   */
46
  public function label() {
47
48
    return $this->get('title')->value;
  }
49

50
51
52
  /**
   * {@inheritdoc}
   */
53
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
54
55
56
    $fields['iid'] = FieldDefinition::create('integer')
      ->setLabel(t('Aggregator item ID'))
      ->setDescription(t('The ID of the feed item.'))
57
58
      ->setReadOnly(TRUE)
      ->setSetting('unsigned', TRUE);
59
60
61
62

    $fields['fid'] = FieldDefinition::create('entity_reference')
      ->setLabel(t('Aggregator feed ID'))
      ->setDescription(t('The ID of the aggregator feed.'))
63
      ->setSetting('target_type', 'aggregator_feed');
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

    $fields['title'] = FieldDefinition::create('string')
      ->setLabel(t('Title'))
      ->setDescription(t('The title of the feed item.'));

    $fields['langcode'] = FieldDefinition::create('language')
      ->setLabel(t('Language code'))
      ->setDescription(t('The feed item language code.'));

    $fields['link'] = FieldDefinition::create('uri')
      ->setLabel(t('Link'))
      ->setDescription(t('The link of the feed item.'));

    $fields['author'] = FieldDefinition::create('string')
      ->setLabel(t('Author'))
      ->setDescription(t('The author of the feed item.'));

    // @todo Convert to a text field in https://drupal.org/node/2149845.
    $fields['description'] = FieldDefinition::create('string')
      ->setLabel(t('Description'))
      ->setDescription(t('The body of the feed item.'));

86
    $fields['timestamp'] = FieldDefinition::create('created')
87
88
89
90
91
92
93
94
      ->setLabel(t('Posted timestamp'))
      ->setDescription(t('Posted date of the feed item, as a Unix timestamp.'));

    // @todo Convert to a real UUID field in https://drupal.org/node/2149851.
    $fields['guid'] = FieldDefinition::create('string')
      ->setLabel(t('GUID'))
      ->setDescription(t('Unique identifier for the feed item.'));

95
96
    return $fields;
  }
97

98
  /**
99
   * {@inheritdoc}
100
101
   */
  public function getFeedId() {
102
    return $this->get('fid')->target_id;
103
104
105
  }

  /**
106
   * {@inheritdoc}
107
108
109
110
111
112
   */
  public function setFeedId($fid) {
    return $this->set('fid', $fid);
  }

  /**
113
   * {@inheritdoc}
114
115
116
117
118
119
   */
  public function getTitle() {
    return $this->get('title')->value;
  }

  /**
120
   * {@inheritdoc}
121
122
123
124
125
126
   */
  public function setTitle($title) {
    return $this->set('title', $title);
  }

  /**
127
   * {@inheritdoc}
128
129
130
131
132
133
   */
  public function  getLink() {
    return $this->get('link')->value;
  }

  /**
134
   * {@inheritdoc}
135
136
137
138
139
140
   */
  public function setLink($link) {
    return $this->set('link', $link);
  }

  /**
141
   * {@inheritdoc}
142
143
144
145
146
147
   */
  public function getAuthor() {
    return $this->get('author')->value;
  }

  /**
148
   * {@inheritdoc}
149
150
151
152
153
154
   */
  public function setAuthor($author) {
    return $this->set('author', $author);
  }

  /**
155
   * {@inheritdoc}
156
157
158
159
160
161
   */
  public function getDescription() {
    return $this->get('description')->value;
  }

  /**
162
   * {@inheritdoc}
163
164
165
166
167
168
   */
  public function setDescription($description) {
    return $this->set('description', $description);
  }

  /**
169
   * {@inheritdoc}
170
171
172
173
174
175
   */
  public function getPostedTime() {
    return $this->get('timestamp')->value;
  }

  /**
176
   * {@inheritdoc}
177
178
179
180
181
182
   */
  public function setPostedTime($timestamp) {
    return $this->set('timestamp', $timestamp);
  }

  /**
183
   * {@inheritdoc}
184
185
186
187
188
189
   */
  public function getGuid() {
    return $this->get('guid')->value;
  }

  /**
190
   * {@inheritdoc}
191
192
193
194
   */
  public function setGuid($guid) {
    return $this->set('guid', $guid);
  }
195
}