1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Donatas Navidonskis <[email protected]> |
5
|
|
|
* @since 2017 |
6
|
|
|
* @class FormEntities |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
class FormEntities extends Form { |
|
|
|
|
10
|
|
|
|
11
|
|
|
public function __construct(Controller $controller, $name, DataList $entities) { |
12
|
|
|
$fields = new FieldList(); |
13
|
|
|
|
14
|
|
|
/** @var LangEntity $entity */ |
15
|
|
|
foreach ($entities as $entity) { |
16
|
|
|
$fields->push( |
17
|
|
|
$entityField = TextField::create("Entities[{$entity->ID}]", $entity->Namespace, $entity->Value) |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
if (! empty($entity->Title)) { |
21
|
|
|
$entityField->setRightTitle($entity->Title); |
22
|
|
|
$entityField->setAttribute('title', $entity->Namespace); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$actions = new FieldList([ |
27
|
|
|
$button = new FormAction('doSave', _t('FormEntities.SAVE', 'Save')), |
28
|
|
|
]); |
29
|
|
|
|
30
|
|
|
$button->addExtraClass('action ss-ui-action-constructive ss-ui-button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary'); |
31
|
|
|
|
32
|
|
|
parent::__construct($controller, $name, $fields, $actions, null); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function doSave(array $data = [], Form $form) { |
36
|
|
|
if (array_key_exists('Entities', $data) && $data['Entities'] > 0) { |
37
|
|
|
foreach ($data['Entities'] as $id => $value) { |
38
|
|
|
/** @var LangEntity $entity */ |
39
|
|
|
$entity = LangEntity::get()->byID($id); |
40
|
|
|
$entity->Value = $value; |
41
|
|
|
$entity->write(); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (! Director::is_ajax()) { |
46
|
|
|
return $form->getController()->redirectBack(); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.