FOF30\Factory\BasicFactory::getFormFilename PHP Method

getFormFilename() protected method

Tries to find the absolute file path for an abstract form filename. For example, it may convert form.default to home/myuser/mysite/components/com_foobar/View/tmpl/form.default.xml.
protected getFormFilename ( string $source, string $viewName = null ) : string | boolean
$source string The abstract form filename
$viewName string The name of the view we're getting the path for
return string | boolean The fill path to the form XML file or boolean false if it's not found
    protected function getFormFilename($source, $viewName = null)
    {
        if (empty($source)) {
            return false;
        }
        $componentName = $this->container->componentName;
        if (empty($viewName)) {
            $viewName = $this->container->dispatcher->getController()->getView()->getName();
        }
        $viewNameAlt = $this->container->inflector->singularize($viewName);
        if ($viewNameAlt == $viewName) {
            $viewNameAlt = $this->container->inflector->pluralize($viewName);
        }
        $componentPaths = $this->container->platform->getComponentBaseDirs($componentName);
        $file_root = $componentPaths['main'];
        $alt_file_root = $componentPaths['alt'];
        $template_root = $this->container->platform->getTemplateOverridePath($componentName);
        // Basic paths we need to always search
        $paths = array($template_root . '/' . $viewName, $template_root . '/' . $viewNameAlt, $file_root . '/ViewTemplates/' . $viewName, $file_root . '/ViewTemplates/' . $viewNameAlt, $file_root . '/View/' . $viewName . '/tmpl', $file_root . '/View/' . $viewNameAlt . '/tmpl');
        // The other side of the component
        if ($this->formLookupInOtherSide) {
            // Forms inside the specialized folder for easier template overrides
            $paths[] = $alt_file_root . '/ViewTemplates/' . $viewName;
            $paths[] = $alt_file_root . '/ViewTemplates/' . $viewNameAlt;
            $paths[] = $alt_file_root . '/View/' . $viewName . '/tmpl';
            $paths[] = $alt_file_root . '/View/' . $viewNameAlt . '/tmpl';
        }
        // Legacy paths, this side of the component
        $paths[] = $file_root . '/views/' . $viewName . '/tmpl';
        $paths[] = $file_root . '/views/' . $viewNameAlt . '/tmpl';
        $paths[] = $file_root . '/Model/forms';
        $paths[] = $file_root . '/models/forms';
        // Legacy paths, the other side of the component
        if ($this->formLookupInOtherSide) {
            $paths[] = $file_root . '/views/' . $viewName . '/tmpl';
            $paths[] = $file_root . '/views/' . $viewNameAlt . '/tmpl';
            $paths[] = $file_root . '/Model/forms';
            $paths[] = $file_root . '/models/forms';
        }
        $paths = array_unique($paths);
        // Set up the suffixes to look into
        $suffixes = array();
        $temp_suffixes = $this->container->platform->getTemplateSuffixes();
        if (!empty($temp_suffixes)) {
            foreach ($temp_suffixes as $suffix) {
                $suffixes[] = $suffix . '.xml';
            }
        }
        $suffixes[] = '.xml';
        // Look for all suffixes in all paths
        $result = false;
        $filesystem = $this->container->filesystem;
        foreach ($paths as $path) {
            foreach ($suffixes as $suffix) {
                $filename = $path . '/' . $source . $suffix;
                if ($filesystem->fileExists($filename)) {
                    $result = $filename;
                    break;
                }
            }
            if ($result) {
                break;
            }
        }
        return $result;
    }