1 | <?php |
||
18 | class FileFormFactory extends AssetFormFactory |
||
19 | { |
||
20 | protected function getFormFieldTabs($record, $context = []) |
||
21 | { |
||
22 | // Add extra tab |
||
23 | $tabs = TabSet::create( |
||
24 | 'Editor', |
||
25 | $this->getFormFieldDetailsTab($record, $context), |
||
26 | $this->getFormFieldUsageTab($record, $context), |
||
27 | $this->getFormFieldHistoryTab($record, $context) |
||
28 | ); |
||
29 | |||
30 | // All non-admin forms are typically readonly |
||
31 | switch ($this->getFormType($context)) { |
||
32 | case static::TYPE_INSERT: |
||
33 | $tabs->setReadonly(true); |
||
34 | $tabs->unshift($this->getFormFieldAttributesTab($record, $context)); |
||
35 | break; |
||
36 | case static::TYPE_SELECT: |
||
37 | $tabs->setReadonly(true); |
||
38 | break; |
||
39 | } |
||
40 | |||
41 | return $tabs; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Build "Usage" tab |
||
46 | * |
||
47 | * @param File $record |
||
48 | * @param array $context |
||
49 | * @return Tab |
||
50 | */ |
||
51 | protected function getFormFieldUsageTab($record, $context = []) |
||
52 | { |
||
53 | // Add new tab for usage |
||
54 | return Tab::create( |
||
55 | 'Usage', |
||
56 | DatetimeField::create("Created", _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CREATED', 'First uploaded')) |
||
57 | ->setReadonly(true), |
||
58 | DatetimeField::create("LastEdited", _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.LASTEDIT', 'Last changed')) |
||
59 | ->setReadonly(true) |
||
60 | ); |
||
61 | } |
||
62 | |||
63 | protected function getFormFieldDetailsTab($record, $context = []) |
||
64 | { |
||
65 | // Update details tab |
||
66 | $tab = Tab::create( |
||
67 | 'Details', |
||
68 | TextField::create("Title", File::singleton()->fieldLabel('Title')), |
||
69 | TextField::create('Name', File::singleton()->fieldLabel('Filename')), |
||
70 | ReadonlyField::create("Path", _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.PATH', 'Path'), $this->getPath($record)) |
||
71 | ); |
||
72 | |||
73 | if ($this->getFormType($context) !== static::TYPE_ADMIN) { |
||
74 | $tab->push(LiteralField::create( |
||
75 | 'EditLink', |
||
76 | sprintf( |
||
77 | '<a href="%s" class="%s" target="_blank"><i class="%s" />%s</a>', |
||
78 | $record->CMSEditLink(), |
||
79 | 'btn btn-secondary-outline font-icon-edit editor__edit-link', |
||
80 | '', |
||
81 | _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.EditLink', 'Edit original file') |
||
82 | ) |
||
83 | )); |
||
84 | } |
||
85 | return $tab; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Create tab for file attributes |
||
90 | * |
||
91 | * @param File $record |
||
92 | * @param array $context |
||
93 | * @return Tab |
||
94 | */ |
||
95 | protected function getFormFieldAttributesTab($record, $context = []) |
||
96 | { |
||
97 | return Tab::create( |
||
98 | 'Placement', |
||
99 | LiteralField::create( |
||
100 | 'AttributesDescription', |
||
101 | '<p>'. _t( |
||
102 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AttributesDescription', |
||
103 | 'These changes will only affect this particular placement of the file.' |
||
104 | ) .'</p>' |
||
105 | ), |
||
106 | TextField::create('Caption', _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.Caption', 'Caption')) |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | protected function getFormFieldHistoryTab($record, $context = []) |
||
111 | { |
||
112 | return Tab::create( |
||
113 | 'History', |
||
114 | HistoryListField::create('HistoryList') |
||
115 | ->setRecord($record) |
||
116 | ); |
||
117 | } |
||
118 | |||
119 | protected function getFormFields(Controller $controller, $name, $context = []) |
||
120 | { |
||
121 | /** @var File $record */ |
||
122 | $record = $context['Record']; |
||
123 | |||
124 | // Add status flag before extensions are triggered |
||
125 | $this->beforeExtending('updateFormFields', function (FieldList $fields) use ($record) { |
||
126 | // @todo move specs to a component/class, so it can update specs when a File is replaced |
||
127 | $fields->insertAfter( |
||
128 | 'TitleHeader', |
||
129 | LiteralField::create('FileSpecs', $this->getSpecsMarkup($record)) |
||
130 | ); |
||
131 | $fields->push(HiddenField::create('FileFilename')); |
||
132 | $fields->push(HiddenField::create('FileHash')); |
||
133 | $fields->push(HiddenField::create('FileVariant')); |
||
134 | }); |
||
135 | |||
136 | return parent::getFormFields($controller, $name, $context); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Get publish action |
||
141 | * |
||
142 | * @param File $record |
||
143 | * @return FormAction |
||
144 | */ |
||
145 | protected function getPublishAction($record) |
||
146 | { |
||
147 | if (!$record || !$record->canPublish()) { |
||
148 | return null; |
||
149 | } |
||
150 | |||
151 | // Build action |
||
152 | $publishText = _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.PUBLISH_BUTTON', 'Publish'); |
||
153 | return FormAction::create('publish', $publishText) |
||
154 | ->setIcon('rocket') |
||
155 | ->setSchemaData(['data' => ['buttonStyle' => 'primary']]); |
||
156 | } |
||
157 | |||
158 | protected function getFormActions(Controller $controller, $formName, $context = []) |
||
159 | { |
||
160 | $record = $context['Record']; |
||
161 | |||
162 | if ($this->getFormType($context) !== static::TYPE_ADMIN) { |
||
163 | $actions = new FieldList(array_filter([ |
||
164 | $this->getInsertAction($record), |
||
165 | ])); |
||
166 | } else { |
||
167 | // Build top level bar |
||
168 | $actions = new FieldList(array_filter([ |
||
169 | FieldGroup::create(array_filter([ |
||
170 | $this->getSaveAction($record), |
||
171 | $this->getPublishAction($record) |
||
172 | ])) |
||
173 | ->setName('Actions') |
||
174 | ->addExtraClass('btn-group'), |
||
175 | $this->getPopoverMenu($record), |
||
176 | ])); |
||
177 | } |
||
178 | |||
179 | // Update |
||
180 | $this->invokeWithExtensions('updateFormActions', $actions, $controller, $formName, $context); |
||
181 | return $actions; |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * get HTML for status icon |
||
186 | * |
||
187 | * @param File $record |
||
188 | * @return null|string |
||
189 | */ |
||
190 | protected function getSpecsMarkup($record) |
||
201 | |||
202 | /** |
||
203 | * Get published status flag |
||
204 | * |
||
205 | * @param File $record |
||
206 | * @return null|string |
||
207 | */ |
||
208 | protected function getStatusFlagMarkup($record) |
||
215 | |||
216 | /** |
||
217 | * Get user-visible "Path" for this record |
||
218 | * |
||
219 | * @param File $record |
||
220 | * @return string |
||
221 | */ |
||
222 | protected function getPath($record) |
||
233 | |||
234 | /** |
||
235 | * Get action for publishing |
||
236 | * |
||
237 | * @param File $record |
||
238 | * @return FormAction |
||
239 | */ |
||
240 | protected function getUnpublishAction($record) |
||
241 | { |
||
255 | |||
256 | /** |
||
257 | * Get actions that go into the Popover menu |
||
258 | * |
||
259 | * @param $record |
||
260 | * @return array |
||
261 | */ |
||
262 | protected function getPopoverActions($record) |
||
271 | |||
272 | /** |
||
273 | * @param File $record |
||
274 | * @return FormAction |
||
275 | */ |
||
276 | protected function getInsertAction($record) |
||
284 | } |
||
285 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.