Automatic config screen generator.

@param  \BBCMS\Models\Module  $module
@param  string  $action
@return array
336638
public static function generate_page(Module $module, string $action)
    {
        $settings = static::query()->where('module_name', $module->name)
            ->where('action', $action)->get()->makeFormFields();

        return [
            'module' => $module,
            'sections' => $settings->pluck('section')->unique(),
            'fieldsets' => $settings->pluck('fieldset')->unique(),
            'fields' => $settings->groupBy(['section', 'fieldset']),
        ];
    }
497950
public static function isModule(string $module, string $controller = null, string $action = null): bool
    {
        $route = Application::route();
        if ($module === $route->getModuleUrl()) {
            if ($controller === null) {
                return true;
            } else {
                if ($controller === $route->getControllerUrl()) {
                    // now we have matched module and controller
                    if ($action === null) {
                        return true;
                    } else {
                        return ($action === $route->getActionUrl());
                    }
                } else {
                    return false;
                }
            }
        } else {
            return false;
        }
    }
1070173
private function getIndexesByModule($module)
    {
        // Indexes to be removed
        $indexes = array();

        foreach ($this->data as $index => $row) {
            if (isset($row[ConstProviderInterface::CONFIG_PARAM_MODULE]) && $row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module) {
                array_push($indexes, $index);
            }
        }

        return $indexes;
    }
1162136
protected function getModuleConfig(string $module, string $view, array $options = []): ModuleConfig
    {
        $mc = new ModuleConfig(ConfigType::VIEW(), $module, $view, ['cacheSkip' => true]);

        $schema = $mc->createSchema(['lint' => true]);
        $schema->setCallback(function (array $schema) use ($module) {
            //Add fields from migration file
            $schema = $this->addFieldsToSchema($schema, $module);
            //Add relation fields
            $schema = $this->addRelationToSchema($schema, $module);

            return $schema;
        });

        $mc->setParser(new Parser($schema, ['lint' => true, 'validate' => true]));

        return $mc;
    }
52951
protected function getRightsFromMap($controller, $action, $module) {
        list ($rController, $allController) = $this->getRawAndModuleControllers($controller, $module);
        if (isset($this->finalMap[$rController][$action])) {
            return $this->finalMap[$rController][$action];
        } elseif (isset($this->finalMap[$allController][$action])) {
            return $this->finalMap[$allController][$action];
        } elseif (isset($this->finalMap[$rController]['*'])) {
            return $this->finalMap[$rController]['*'];
        } elseif (isset($this->finalMap[$allController]['*'])) {
            return $this->finalMap[$allController]['*'];
        } elseif (isset($this->finalMap['*'][$action])) {
            return $this->finalMap['*'][$action];
        } elseif (isset($this->finalMap['*']['*'])) {
            return $this->finalMap['*']['*'];
        } else {
            return array('*');
        }
    }
1017714
protected function createModal($action)
    {
        $modal = new Modal(sprintf('%s.header.%s', $this->config->getId(), $action));

        $buttons = [];

        if (in_array($action, ['new', 'edit', 'remove'])) {
            $submitButton = [
                'id'       => 'submit',
                'label'    => 'ekyna_core.button.save',
                'icon'     => 'glyphicon glyphicon-ok',
                'cssClass' => 'btn-success',
                'autospin' => true,
            ];
            if ($action === 'edit') {
                $submitButton['icon'] = 'glyphicon glyphicon-ok';
                $submitButton['cssClass'] = 'btn-warning';
            } elseif ($action === 'remove') {
                $submitButton['label'] = 'ekyna_core.button.remove';
                $submitButton['icon'] = 'glyphicon glyphicon-trash';
                $submitButton['cssClass'] = 'btn-danger';
            }
            $buttons[] = $submitButton;
        }

        $buttons[] = [
            'id' => 'close',
            'label' => 'ekyna_core.button.cancel',
            'icon' => 'glyphicon glyphicon-remove',
            'cssClass' => 'btn-default',
        ];

        $modal->setButtons($buttons);

        return $modal;
    }
492279
private function getRawAndModuleControllers($controller, $module) {
        if ('/' == $module || '' == $module) {
            $rController = $controller;
            $allController = '*';
        } elseif (null === $module) {
            $rController = \mpf\WebApp::get()->request()->getModule() . '/' . $controller;
            $allController = \mpf\WebApp::get()->request()->getModule() . '/*';
        } else {
            $rController = $module . '/' . $controller;
            $allController = $module . '/*';
        }
        return array($rController, $allController);
    }
249492
protected function _getControllerActionConfiguration($actionName, $config)
    {
        $realAction = Hash::get($config, 'url.action', $actionName);
        if ($this->_crud()->isActionMapped($realAction)) {
            $action = $this->_action($realAction);
            $class = get_class($action);
            $class = substr($class, strrpos($class, '\\') + 1);

            if ($class === 'DeleteAction') {
                $config += ['method' => 'DELETE'];
            }

            if (!isset($config['scope'])) {
                $config['scope'] = $class === 'AddAction' ? 'table' : $action->scope();
            }
        }

        // apply defaults if necessary
        $scope = isset($config['scope']) ? $config['scope'] : 'entity';
        $method = isset($config['method']) ? $config['method'] : 'GET';

        $title = !empty($config['link_title']) ? $config['link_title'] : Inflector::humanize(Inflector::underscore($actionName));
        $url = ['action' => $realAction];
        if (isset($config['url'])) {
            $url = $config['url'] + $url;
        }

        $actionConfig = [
            'title' => $title,
            'url' => $url,
            'method' => $method,
            'options' => array_diff_key(
                $config,
                array_flip(['method', 'scope', 'link_title', 'url', 'scaffold', 'callback'])
            )
        ];
        if (!empty($config['callback'])) {
            $actionConfig['callback'] = $config['callback'];
        }

        return [$scope, $actionConfig];
    }
1170674
public function displayModuleOnAllPages($module)
	{
		$this->amOnPage('administrator/index.php?option=com_modules');
		$this->searchForItem($module);
		$this->click(array('link' => $module));
		$this->waitForElement(array('link' => 'Menu Assignment'), 30);
		$this->click(array('link' => 'Menu Assignment'));
		$this->waitForElement(array('id' => 'jform_menus-lbl'), 30);
		$this->click(array('id' => 'jform_assignment_chzn'));
		$this->click(array('xpath' => "//li[@data-option-array-index='0']"));
		$this->click(array('xpath' => "//div[@id='toolbar-apply']/button"));
		$this->waitForText('Module saved', 30, array('id' => 'system-message-container'));
	}
293142
protected function generateModules(array $config, array $modules, ?GridIterator $iterator = null): array
    {
        $buffer = [];

        foreach ($config as $entry) {
            if ($entry['inactive'] || !$entry['module']) {
                continue;
            }

            if (is_numeric($entry['module'])) {
                if (!empty($modules[$entry['module']])) {
                    $buffer[] = $modules[$entry['module']];
                }

                continue;
            }

            if ($iterator) {
                $iterator->next();

                foreach ($iterator->resets() as $reset) {
                    $buffer[] = '<div class="clearfix w-100 ' . $reset . '"></div>';
                }

                $buffer[] = sprintf(
                    "\n" . '</div>' . "\n" . '<div class="%s">',
                    $iterator->current()
                );
            }
        }

        return $buffer;
    }
1269478
protected static function _loadModulesConfig( )
		{
			$config = array( '..' , '.' );
			foreach ( static::options( ) as $key => $val )
			{
				$config[ ] = $key . '.php';
			}
			foreach ( Module::all( ) as $k => $module )
			{
				$scanned_directory = array_diff( scandir( ptc_path( 'root' ) . '/modules/' . $k . '/config' ) , $config );
				if ( !empty( $scanned_directory ) )
				{
					foreach ( $scanned_directory as $file )
					{
						$option_name = str_replace( '.php' , '' , $file );
						$options = require( ptc_path( 'root' ) . '/modules/' . $k . '/config/' . $file );
						if ( ptc_array_get( $options , '_load' ) )
						{
							$options = call_user_func( ptc_array_get( $options , '_load' ) , $options );
						}
						static::option( $option_name , $options );
					}
				}
			}
		}
11379
public function hasPermission($module, $action, User $user = null) {
		$module = $this->service->getModuleManager()->load($module);
		$action = $module->getActionModel($action);
		return $this->hasActionPermission($action, $user);
	}
160117
public function relatedModels($related = null, $action = null)
    {
        if ($related === null) {
            return $this->_action($action)->getConfig('relatedModels');
        }

        return $this->_action($action)->setConfig('relatedModels', $related, false);
    }
837218
protected function getEditButtons(Action $action, EnvironmentInterface $environment)
    {
        $translator = $environment->getTranslator();

        $mode = $this->getMode($action);

        $buttons = [];

        $buttons['save'] = \sprintf(
            '<input type="submit" name="%s_save" id="%s_save" class="tl_submit" accesskey="s" value="%s" />',
            $mode,
            $mode,
            $translator->translate('MSC.save')
        );

        $buttons['save'] .= '&nbsp;';

        $buttons['save'] .= \sprintf(
            '<input type="submit" name="%s_saveNback" id="%s_saveNback" class="tl_submit" accesskey="c" value="%s" />',
            $mode,
            $mode,
            $translator->translate('MSC.saveNback')
        );

        $submitButtonTemplate = new ContaoBackendViewTemplate('dc_general_submit_button');
        $submitButtonTemplate->setData($buttons);

        return \preg_replace('/(\s\s+|\t|\n)/', '', $submitButtonTemplate->parse());
    }
1204591
protected function initContainer($module)
    {
        $map = [];

        $defaultClassMap = [

            /* MODELS */
            'Form' => Form::class,
            'FormSettings' => FormSettings::class,
            'FormSettingsLang' => FormSettingsLang::class,

            /* QUERIES */
            'FormQuery' => FormQuery::class,
            'FormSettingsQuery' => FormSettingsQuery::class,
            'FormSettingsLangQuery' => FormSettingsLangQuery::class,

            /* SEARCH */
            'FormSearch' => FormSearch::class
        ];

        $routes = [
            'mrstroz\\wavecms\\form\\models' => [
                'Form',
                'FormSettings',
                'FormSettingsLang',
            ],
            'mrstroz\\wavecms\\models\\form\\query' => [
                'FormQuery',
                'FormSettingsQuery',
                'FormSettingsLangQuery',
            ],
            'mrstroz\\wavecms\\models\\form\\search' => [
                'FormSearch'
            ]
        ];
        $mapping = array_merge($defaultClassMap, $module->classMap);

        foreach ($mapping as $name => $definition) {
            $map[$this->getContainerRoute($routes, $name) . "\\$name"] = $definition;
        }

        $di = Yii::$container;

        foreach ($map as $class => $definition) {
            /** Check if definition does not exist in container. */
            if (!$di->has($class)) {
                $di->set($class, $definition);
            }
        }

    }
647138
function getActionComponentConfig(entityName) {
            var components = {};

            u.each(
                ['List', 'Form', 'Success', 'Read', 'Detail'],
                function (type) {
                    var action = entityName + type;
                    var model = action + 'Model';
                    var view = action + 'View';

                    components[action] = {
                        module: entityName + '/' + type,
                        args: [entityName],
                        auto: true,
                        properties: {
                            model: {$ref: model},
                            view: {$ref: view}
                        }
                    };

                    var modelPropperties = {
                        data: {$ref: entityName + 'Data'}
                    };

                    if (type === 'Form') {
                        modelPropperties.validator = {$ref: entityName + 'EntityValidator'};
                    }

                    components[model] = {
                        module: entityName + '/' + type + 'Model',
                        auto: true,
                        properties: modelPropperties
                    };

                    components[view] = {
                        module: entityName + '/' + type + 'View',
                        auto: true
                    };
                }
            );

            return components;
        }
1108794
protected function renderTemplate(Action $action, array $config)
    {
        $template = new ContaoBackendViewTemplate('dcbe_general_edit');
        $template->setData($config);

        $template->set('mode', $this->getMode($action));

        return $template->parse();
    }