1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\Driver\Cores; |
4
|
|
|
|
5
|
|
|
use Drupal\Component\Utility\Random; |
6
|
|
|
use Symfony\Component\DependencyInjection\Container; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Base class for core drivers. |
10
|
|
|
*/ |
11
|
|
|
abstract class AbstractCore implements CoreInterface { |
12
|
|
|
/** |
13
|
|
|
* System path to the Drupal installation. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $drupalRoot; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* URI for the Drupal installation. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $uri; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Random generator. |
28
|
|
|
* |
29
|
|
|
* @var \Drupal\Component\Utility\Random |
30
|
|
|
*/ |
31
|
|
|
protected $random; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function __construct($drupal_root, $uri = 'default', Random $random = NULL) { |
37
|
|
|
|
38
|
|
|
$this->drupalRoot = realpath($drupal_root); |
39
|
|
|
$this->uri = $uri; |
40
|
|
|
if (!isset($random)) { |
41
|
|
|
$random = new Random(); |
42
|
|
|
} |
43
|
|
|
$this->random = $random; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function getRandom() { |
50
|
|
|
|
51
|
|
|
return $this->random; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function getFieldHandler($entity, $entity_type, $field_name) { |
58
|
|
|
|
59
|
|
|
$reflection = new \ReflectionClass($this); |
60
|
|
|
$core_namespace = $reflection->getShortName(); |
61
|
|
|
$field_types = $this->getEntityFieldTypes($entity_type); |
62
|
|
|
$camelized_type = Container::camelize($field_types[$field_name]); |
63
|
|
|
$default_class = sprintf('\Drupal\Driver\Fields\%s\DefaultHandler', $core_namespace); |
64
|
|
|
$class_name = sprintf('\Drupal\Driver\Fields\%s\%sHandler', $core_namespace, $camelized_type); |
65
|
|
|
if (class_exists($class_name)) { |
66
|
|
|
return new $class_name($entity, $entity_type, $field_name); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return new $default_class($entity, $entity_type, $field_name); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Expands properties on the given entity object to the expected structure. |
74
|
|
|
* |
75
|
|
|
* @param \stdClass $entity |
76
|
|
|
* Entity object. |
77
|
|
|
*/ |
78
|
|
|
protected function expandEntityFields($entity_type, \stdClass $entity) { |
79
|
|
|
|
80
|
|
|
$field_types = $this->getEntityFieldTypes($entity_type); |
81
|
|
|
foreach ($field_types as $field_name => $type) { |
82
|
|
|
if (isset($entity->$field_name)) { |
83
|
|
|
$entity->$field_name = $this->getFieldHandler($entity, $entity_type, $field_name) |
84
|
|
|
->expand($entity->$field_name); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function clearStaticCaches() { |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
|
|
public function nodeAlter($node, $values) { |
100
|
|
|
|
101
|
|
|
throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__)); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
*/ |
107
|
|
|
public function userAlter($user, $values) { |
108
|
|
|
|
109
|
|
|
throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__)); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
*/ |
115
|
|
|
public function nodeDeleteMultiple(array $nids) { |
116
|
|
|
|
117
|
|
|
throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__)); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritdoc} |
122
|
|
|
*/ |
123
|
|
|
public function userDeleteMultiple(array $uids) { |
124
|
|
|
|
125
|
|
|
throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__)); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
} |
129
|
|
|
|