Article.php 1.67 KB
Newer Older
Mateu Aguiló Bosch's avatar
Mateu Aguiló Bosch committed
1
2
3
4
<?php

/**
 * @file
5
 * Contains \Drupal\typed_entity_example\TypedEntity\Node\Article.
Mateu Aguiló Bosch's avatar
Mateu Aguiló Bosch committed
6
7
 */

8
namespace Drupal\typed_entity_example\TypedEntity\Node;
Mateu Aguiló Bosch's avatar
Mateu Aguiló Bosch committed
9
10
11

use Drupal\typed_entity\TypedEntity\TypedEntityInterface;
use Drupal\typed_entity\TypedEntity\TypedEntityManager;
12
use Drupal\typed_entity_example\TypedEntity\TypedNode;
Mateu Aguiló Bosch's avatar
Mateu Aguiló Bosch committed
13

14
class Article extends TypedNode implements ArticleInterface {
Mateu Aguiló Bosch's avatar
Mateu Aguiló Bosch committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

  /**
   * The article image.
   *
   * @var TypedEntityInterface
   */
  protected $image;

  /**
   * {@inheritdoc}
   */
  public function getImage() {
    if (isset($this->image)) {
      return $this->image;
    }
    if (!$items = field_get_items($this->getEntityType(), $this->getEntity(), 'field_image')) {
      return NULL;
    }
    $item = reset($items);
    $file_id = $item['fid'];
Pablo López's avatar
Pablo López committed
35
    return TypedEntityManager::create('file', entity_load_single('file', $file_id));
Mateu Aguiló Bosch's avatar
Mateu Aguiló Bosch committed
36
37
  }

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  /**
   * {@inheritdoc}
   */
  public function getLoggingMessage() {
    $node = $this->getEntity();
    return $this::t('User with id @uid. Node with title @title. Status @status.', array(
      '@uid' => $node->uid,
      '@title' => $node->title,
      '@status' => $node->status,
    ));
  }

  /**
   * Wraps the translation function to allow overriding for unit testing.
   *
   * @param $string
   *   A string containing the English string to translate.
   * @param $args
   *   An associative array of replacements to make after translation. Based
   *   on the first character of the key, the value is escaped and/or themed.
   *   See format_string() for details.
   *
   * @return string
   *   The translated string.
   */
  protected static function t($string, array $args = array()) {
    return t($string, $args);
  }
Mateu Aguiló Bosch's avatar
Mateu Aguiló Bosch committed
66
}