-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAcfConfig.php
More file actions
82 lines (70 loc) · 2.25 KB
/
Copy pathAcfConfig.php
File metadata and controls
82 lines (70 loc) · 2.25 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php namespace ProcessWire;
use \DirectoryIterator;
abstract class AcfConfig extends WireData implements Module {
/** @var AdminCustomFiles $adminCustomFiles */
protected $adminCustomFiles = null;
/** @var Page $adminCustomFiles */
protected $editPage = null;
/** @var Page $adminCustomFiles */
protected $editTemplate = null;
private function setFromPageEditor() {
/** @var Process */
$process = $this->process;
if ($process instanceof WirePageEditor && method_exists($process, 'getPage')) {
$this->editPage = $process->getPage();
// Some classes extending WirePageEditor do not have a template like
$this->editTemplate = $this->editPage->template
? $this->editPage->template
: new Template();;
}
}
/**
* Constructs the abstract base class
*
* @param AdminCustomFiles $acf
*/
public function __construct(AdminCustomFiles $acf) {
$this->adminCustomFiles = $acf;
$this->editPage = new NullPage();
$this->editTemplate = new Template();
$this->setFromPageEditor();
}
public function setConfigJS() {
/** @var Config */
$config = $this->wire('config');
$array = $this->jsConfig();
if (!is_array($array)) {
$subject = $this->className() . "::jsConfig()";
$this->error(sprintf($this->_('%1$s should return an “array”, %2$s given.'), $subject, gettype($array)), true);
$this->warning($this->_('Setting $config->js->AdminCustomFiles skipped.'));
return false;
}
/** Sets adminCustomFiles to config.js */
$config->js($this->adminCustomFiles->className(), $array);
}
/**
* Ready
*
* The descending AcfConfig module can overwrite this method when it is
* desirable. We call this method when AcfConfig is ready. (All reuired
* properties are set)
*
* @var AdminCustomFiles $this->adminCustomFiles
* @var Page|User|NullPage $this->editPage
* @var Template $this->editTemplate (see: $this->setFromPageEditor)
* @return void
*/
public function ready() {}
/**
* Javascript Config
*
* The descending AcfConfig module should return an array that is ready to
* be used in $this->wire('config')->js('AdminCustomFiles', $array);
*
* This is an abstract method that descending AcfConfig module classes are
* required to implement.
*
* @return array
*/
abstract function jsConfig();
}