/** * @return array */ public function getFieldTypes($extension = null) { //todo cache this if (!$this->fieldTypes) { $this->fieldTypes = []; /** @noinspection PhpUnusedLocalVariableInspection */ $app = App::getInstance(); //available for index.php files $paths = []; foreach (App::module() as $module) { if ($module->get('fieldtypes')) { $paths = array_merge($paths, glob(sprintf('%s/%s/*/index.php', $module->path, $module->get('fieldtypes')), GLOB_NOSORT) ?: []); } } foreach ($paths as $p) { $package = array_merge(['id' => '', 'path' => dirname($p), 'main' => '', 'extensions' => $this->fieldExtensions, 'class' => '\\Bixie\\Framework\\FieldType\\FieldType', 'resource' => 'bixie/framework:app/bundle', 'config' => ['hasOptions' => 0, 'readonlyOptions' => 0, 'required' => 0, 'multiple' => 0], 'dependancies' => [], 'styles' => [], 'getOptions' => '', 'prepareValue' => '', 'formatValue' => ''], include $p); $this->registerFieldType($package); } } if ($extension) { return array_filter($this->fieldTypes, function ($fieldType) use($extension) { /** @var FieldTypeBase $fieldType */ return in_array($extension, $fieldType->getExtensions()); }); } return $this->fieldTypes; }
/** * Defines the plugins callback. * * @param array $options * @return string|null */ public function applyPlugin(array $options) { if (!isset($options['id'])) { return; } $formmaker = App::module('bixie/formmaker'); $app = App::getInstance(); $form_id = $options['id']; unset($options['id']); try { return $formmaker->renderForm($app, $form_id, $options); } catch (App\Exception $e) { return $e->getMessage(); } }
/** * @Route("/{id}", name="form/front") */ public function formAction($id = 0) { if (!($formmaker = App::module('bixie/formmaker'))) { return 'Formmaker extension is disabled!'; } $user = App::user(); /** @var Form $form */ if (!($form = Form::where(['id = ?'], [$id])->where(function ($query) use($user) { if (!$user->isAdministrator()) { $query->where('status = 1'); } })->related('fields')->first())) { App::abort(404, __('Form not found!')); } if (!App::node()->hasAccess(App::user())) { App::abort(403, __('Insufficient User Rights.')); } $app = App::getInstance(); $form->prepareView($app, $formmaker); return ['$view' => ['title' => __($form->title), 'name' => 'bixie/formmaker/form.php'], '$formmaker' => ['config' => $formmaker->publicConfig(), 'formitem' => $form, 'fields' => array_values($form->getFields())], 'node' => App::node()]; }
/** * Constructor. */ public function __construct() { $app = App::getInstance(); $this->installer = new Installer($app); }
/** * @param array|callable $scripts */ protected function run($scripts) { array_map(function ($script) { if (is_callable($script)) { call_user_func($script, App::getInstance()); } }, (array) $scripts); }
/** * @param array|callable $scripts */ public function execute($scripts) { array_map(function ($script) { call_user_func($script, App::getInstance()); }, (array) $scripts); }
/** * Load packages from paths. */ protected function loadPackages() { $app = App::getInstance(); foreach ($this->paths as $path) { $paths = glob($path, GLOB_NOSORT) ?: []; foreach ($paths as $p) { if (!($package = $this->load($p))) { continue; } $this->packages[$package->getName()] = $package; } } }