Пример #1
0
 private function _propertyForm(\Terms $term, $taxonomy)
 {
     Plugin::applyFilters('term_property_form_' . $taxonomy);
     $controls = [];
     $propertiesOpt = Content::getTermPropertiesOpt($taxonomy);
     //form control
     foreach ($propertiesOpt as $key => $setting) {
         if (!$term->isNew()) {
             $setting['value'] = \TermProperty::getTermPropertyValue($term->getId(), $key);
         } else {
             $setting['value'] = '';
         }
         $name = "term_prop[{$key}]";
         $html_options = $setting;
         unset($html_options['label']);
         unset($html_options['value']);
         unset($html_options['control']);
         unset($html_options['options']);
         $controls[$key] = ['label' => isset($setting['label']) ? $setting['label'] : ''];
         switch ($setting['control']) {
             case 'input':
                 $object = new Input($name, $setting['value'], $html_options);
                 $object->setType($setting['type']);
                 unset($html_options['type']);
                 $controls[$key]['controlObject'] = $object;
                 break;
             case 'textarea':
                 $controls[$key]['controlObject'] = new TextArea($name, $setting['value'], $html_options);
                 break;
             case 'select':
                 $object = new SelectOption($name, $setting['value'], $html_options);
                 foreach (@$setting['options'] as $opt) {
                     $object->addOption($opt['label'], $opt['value'], @$opt['htmlOption']);
                 }
                 $controls[$key]['controlObject'] = $object;
                 break;
             case 'checkbox':
                 $object = new Checkbox($name, $setting['value'], $html_options);
                 $object->setExpectValue($setting['default']);
                 $controls[$key]['controlObject'] = $object;
                 break;
             case 'radio':
                 unset($html_options['options']);
                 $object = new RadioButton($name, $setting['value']);
                 foreach (@$setting['options'] as $opt) {
                     $object->add($opt['value'], $opt['label'], @$opt['htmlOption'], @$opt['inputOption']);
                 }
                 $controls[$key]['controlObject'] = $object;
                 break;
         }
     }
     return $controls;
 }
Пример #2
0
 /**
  * Register default taxonomies
  */
 protected function _registerDefaultTaxonomies()
 {
     Plugin::registerTaxonomy('category', 'post', array('label' => t('Category'), 'enable_custom_fields' => true));
     Plugin::registerTaxonomy('banner', 'post', array('label' => t('Banner'), 'enable_custom_fields' => false));
     Plugin::registerTaxonomy('post', 'post', array('label' => t('Post')));
     Plugin::addFilter('term_property_form_category', function () {
         Content::addTermPropertyOpt('cat_view', ['label' => t('Category view'), 'control' => 'select', 'options' => Content::getCategoryTemplates()], 'category');
         Content::addTermPropertyOpt('post_ordering', ['label' => t('Posts ordering'), 'control' => 'select', 'options' => [['label' => t('Created time'), 'value' => 'created_time'], ['label' => t('Publish time'), 'value' => 'publish_time'], ['label' => t('Modified time'), 'value' => 'modified_time'], ['label' => t('Post order'), 'value' => 'ordering'], ['label' => t('Hit'), 'value' => 'hits']]], 'category');
         Content::addTermPropertyOpt('page_size', ['label' => t('Page size'), 'control' => 'input', 'type' => 'text', 'placeholder' => t('Number per page')], 'category');
         Content::addTermPropertyOpt('post_view', ['label' => t('Post view'), 'control' => 'select', 'options' => Content::getPostTemplates()], 'category');
     });
 }