-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathFormFactory.php
57 lines (47 loc) · 1.71 KB
/
FormFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace SilverStripe\LinkField\Form;
use LogicException;
use SilverStripe\Admin\Forms\LinkFormFactory;
use SilverStripe\Forms\HiddenField;
use SilverStripe\LinkField\Type\Type;
use SilverStripe\ORM\DataObject;
use SilverStripe\Dev\Deprecation;
/**
* Create Form schema for the LinkField based on a key provided by the request.
*
* @deprecated 3.0.0 Will be removed without equivalent functionality to replace it
*/
class FormFactory extends LinkFormFactory
{
public function __construct()
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('3.0.0', 'Will be removed without equivalent functionality to replace it', Deprecation::SCOPE_CLASS);
});
}
protected function getFormFields($controller, $name, $context)
{
/** @var Type $type */
$type = $context['LinkType'];
if (!$type instanceof Type) {
throw new LogicException(sprintf('%s: LinkType must be provided and must be an instance of Type', static::class));
}
// Pass on any available link data
$linkData = array_key_exists('LinkData', $context)
? $context['LinkData']
: [];
$fields = $type->scaffoldLinkFields($linkData);
$fields->push(HiddenField::create('typeKey')->setValue($context['LinkTypeKey']));
$this->extend('updateFormFields', $fields, $controller, $name, $context);
return $fields;
}
protected function getValidator($controller, $name, $context)
{
if (!array_key_exists('LinkType', $context)) {
return null;
}
/** @var DataObject|Type $type */
$type = $context['LinkType'];
return $type->getCMSCompositeValidator();
}
}