Backend\Modules\Pages\Engine\Model::getPagesForDropdown PHP Method

getPagesForDropdown() public static method

Get the pages for usage in a dropdown menu
public static getPagesForDropdown ( string $language = null ) : array
$language string The language to use, if not provided we will use the working language.
return array
    public static function getPagesForDropdown($language = null)
    {
        // redefine
        $language = $language !== null ? (string) $language : BL::getWorkingLanguage();
        // get tree
        $levels = self::getTree(array(0), null, 1, $language);
        // init var
        $titles = array();
        $sequences = array();
        $keys = array();
        $return = array();
        // loop levels
        foreach ($levels as $pages) {
            // loop all items on this level
            foreach ($pages as $pageID => $page) {
                // init var
                $parentID = (int) $page['parent_id'];
                // get URL for parent
                $url = isset($keys[$parentID]) ? $keys[$parentID] : '';
                // add it
                $keys[$pageID] = trim($url . '/' . $page['url'], '/');
                // add to sequences
                if ($page['type'] == 'footer') {
                    $sequences['footer'][(string) trim($url . '/' . $page['url'], '/')] = $pageID;
                } else {
                    $sequences['pages'][(string) trim($url . '/' . $page['url'], '/')] = $pageID;
                }
                // get URL for parent
                $title = isset($titles[$parentID]) ? $titles[$parentID] : '';
                $title = trim($title, \SpoonFilter::ucfirst(BL::lbl('Home')) . ' > ');
                // add it
                $titles[$pageID] = trim($title . ' > ' . $page['title'], ' > ');
            }
        }
        if (isset($sequences['pages'])) {
            // sort the sequences
            ksort($sequences['pages']);
            // loop to add the titles in the correct order
            foreach ($sequences['pages'] as $id) {
                if (isset($titles[$id])) {
                    $return[$id] = $titles[$id];
                }
            }
        }
        if (isset($sequences['footer'])) {
            foreach ($sequences['footer'] as $id) {
                if (isset($titles[$id])) {
                    $return[$id] = $titles[$id];
                }
            }
        }
        // return
        return $return;
    }

Usage Example

Example #1
0
 /**
  * Load the form
  */
 protected function loadForm()
 {
     // create form
     $this->frm = new Form('edit');
     $this->frm->addText('title', $this->record['title'], null, 'inputText title', 'inputTextError title');
     $this->frm->addEditor('text', $this->record['text']);
     //$this->frm->addText('link', $this->record['link']);
     $this->frm->addText('linktext', $this->record['linktext']);
     $this->frm->addImage('image');
     // build array with options for the hidden Radiobutton
     $RadiobuttonHiddenValues[] = array('label' => Language::lbl('Hidden'), 'value' => 'Y');
     $RadiobuttonHiddenValues[] = array('label' => Language::lbl('Published'), 'value' => 'N');
     $this->frm->addRadioButton('hidden', $RadiobuttonHiddenValues, $this->record['hidden']);
     // get categories
     $categories = BackendBlocksModel::getCategories();
     $this->frm->addDropdown('category_id', $categories, $this->record['category_id']);
     // meta
     $this->meta = new Meta($this->frm, $this->record['meta_id'], 'title', true);
     $this->meta->setUrlCallBack('Backend\\Modules\\Blocks\\Engine\\Model', 'getUrl', array($this->record['id']));
     // redirect
     $redirectValue = 'none';
     if (isset($this->record['page_id'])) {
         $redirectValue = 'internal';
     }
     if (isset($this->record['link'])) {
         $redirectValue = 'external';
     }
     $redirectValues = array(array('value' => 'none', 'label' => \SpoonFilter::ucfirst(Language::lbl('None'))), array('value' => 'internal', 'label' => \SpoonFilter::ucfirst(Language::lbl('InternalLink')), 'variables' => array('isInternal' => true)), array('value' => 'external', 'label' => \SpoonFilter::ucfirst(Language::lbl('ExternalLink')), 'variables' => array('isExternal' => true)));
     $this->frm->addRadiobutton('redirect', $redirectValues, $redirectValue);
     $this->frm->addDropdown('internal_redirect', BackendPagesModel::getPagesForDropdown(), $redirectValue == 'internal' ? $this->record['page_id'] : null);
     $this->frm->addText('external_redirect', $redirectValue == 'external' ? $this->record['link'] : null, null, null, null, true);
 }
All Usage Examples Of Backend\Modules\Pages\Engine\Model::getPagesForDropdown