|
1
|
|
|
<?php |
|
2
|
|
|
namespace Drupal\Driver\Plugin\DriverEntity; |
|
3
|
|
|
|
|
4
|
|
|
use Drupal\Driver\Plugin\DriverEntityPluginDrupal8Base; |
|
5
|
|
|
use Drupal\Core\Language\LanguageManager; |
|
6
|
|
|
use Drupal\Core\Language\LanguageInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* A driver field plugin used to test selecting an arbitrary plugin. |
|
10
|
|
|
* |
|
11
|
|
|
* @DriverEntity( |
|
12
|
|
|
* id = "configurable_language8", |
|
13
|
|
|
* version = 8, |
|
14
|
|
|
* weight = -100, |
|
15
|
|
|
* entityTypes = { |
|
16
|
|
|
* "configurable_language", |
|
17
|
|
|
* }, |
|
18
|
|
|
* ) |
|
19
|
|
|
*/ |
|
20
|
|
|
class ConfigurableLanguageDrupal8 extends DriverEntityPluginDrupal8Base |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The langcode of the attached language. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
* |
|
28
|
|
|
* @deprecated Use id() instead. |
|
29
|
|
|
*/ |
|
30
|
|
|
public $langcode; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
public function load($entityId) |
|
37
|
|
|
{ |
|
38
|
|
|
$entity = parent::load($entityId); |
|
39
|
|
|
$this->langcode = $this->id(); |
|
|
|
|
|
|
40
|
|
|
return $entity; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
public function save() |
|
47
|
|
|
{ |
|
48
|
|
|
// For new entities, fill in details for known languages. |
|
49
|
|
|
// This is something that ConfigurableLanguage::createFromLangcode() does, in |
|
50
|
|
|
// order to allow enabling a language by langcode alone. |
|
51
|
|
|
if ($this->getEntity()->isNew()) { |
|
52
|
|
|
$langcode = $this->getEntity()->id(); |
|
53
|
|
|
$standard_languages = LanguageManager::getStandardLanguageList(); |
|
54
|
|
|
if (isset($standard_languages[$langcode])) { |
|
55
|
|
|
$label = $this->getEntity()->get('label'); |
|
56
|
|
|
// Label defaults to langcode. |
|
57
|
|
|
if (empty($label) || $label === $langcode) { |
|
58
|
|
|
$this->set('label', $standard_languages[$langcode][0]); |
|
59
|
|
|
} |
|
60
|
|
|
if (empty($this->getEntity()->get('direction'))) { |
|
61
|
|
|
$direction = isset($standard_languages[$langcode][2]) ? $standard_languages[$langcode][2] : LanguageInterface::DIRECTION_LTR; |
|
62
|
|
|
$this->set('direction', $direction); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
parent::save(); |
|
67
|
|
|
$this->langcode = $this->id(); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.