Security update for permissions_by_term
[yaffs-website] / vendor / drupal / drupal-driver / src / Drupal / Driver / Fields / Drupal7 / AbstractHandler.php
1 <?php
2
3 namespace Drupal\Driver\Fields\Drupal7;
4
5 use Drupal\Driver\Fields\FieldHandlerInterface;
6
7 /**
8  * Base class for field handlers in Drupal 7.
9  */
10 abstract class AbstractHandler implements FieldHandlerInterface {
11
12   /**
13    * The entity language.
14    *
15    * @var string
16    */
17   protected $language = NULL;
18
19   /**
20    * The simulated entity.
21    *
22    * @var \stdClass
23    */
24   protected $entity = NULL;
25
26   /**
27    * The entity type.
28    *
29    * @var string
30    */
31   protected $entityType = NULL;
32
33   /**
34    * The field name.
35    *
36    * @var string
37    */
38   protected $fieldName = NULL;
39
40   /**
41    * The field array, as returned by field_read_fields().
42    *
43    * @var array
44    */
45   protected $fieldInfo = array();
46
47   /**
48    * Constructs an AbstractHandler object.
49    *
50    * @param \stdClass $entity
51    *   The simulated entity object containing field information.
52    * @param string $entity_type
53    *   The entity type.
54    * @param string $field_name
55    *   The field name.
56    */
57   public function __construct(\stdClass $entity, $entity_type, $field_name) {
58     $this->entity = $entity;
59     $this->entityType = $entity_type;
60     $this->fieldName = $field_name;
61     $this->fieldInfo = $this->getFieldInfo();
62     $this->language = $this->getEntityLanguage();
63   }
64
65   /**
66    * Magic caller.
67    */
68   public function __call($method, $args) {
69     if ($method == 'expand') {
70       $args['values'] = (array) $args['values'];
71     }
72     return call_user_func_array(array($this, $method), $args);
73   }
74
75   /**
76    * Returns field information.
77    *
78    * @return array
79    *   The field array, as returned by field_read_fields().
80    */
81   public function getFieldInfo() {
82     return field_info_field($this->fieldName);
83   }
84
85   /**
86    * Returns the entity language.
87    *
88    * @return string
89    *   The entity language.
90    */
91   public function getEntityLanguage() {
92     if (field_is_translatable($this->entityType, $this->fieldInfo)) {
93       return entity_language($this->entityType, $this->entity);
94     }
95     return LANGUAGE_NONE;
96   }
97
98 }