3 namespace Drupal\Driver\Fields\Drupal7;
5 use Drupal\Driver\Fields\FieldHandlerInterface;
8 * Base class for field handlers in Drupal 7.
10 abstract class AbstractHandler implements FieldHandlerInterface {
13 * The entity language.
17 protected $language = NULL;
20 * The simulated entity.
24 protected $entity = NULL;
31 protected $entityType = NULL;
38 protected $fieldName = NULL;
41 * The field array, as returned by field_read_fields().
45 protected $fieldInfo = array();
48 * Constructs an AbstractHandler object.
50 * @param \stdClass $entity
51 * The simulated entity object containing field information.
52 * @param string $entity_type
54 * @param string $field_name
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();
68 public function __call($method, $args) {
69 if ($method == 'expand') {
70 $args['values'] = (array) $args['values'];
72 return call_user_func_array(array($this, $method), $args);
76 * Returns field information.
79 * The field array, as returned by field_read_fields().
81 public function getFieldInfo() {
82 return field_info_field($this->fieldName);
86 * Returns the entity language.
89 * The entity language.
91 public function getEntityLanguage() {
92 if (field_is_translatable($this->entityType, $this->fieldInfo)) {
93 return entity_language($this->entityType, $this->entity);