Amiro.CMS API Reference
Amiro.Ru / Manual
Loading search...

The AMI_ModFormView class

AMI_View
   |
   --AMI_ModPlaceholderView
      |
      --AMI_ModFormView

• Introduction

Module form component view abstraction.

• Class synopsis

AMI_ModFormView extends AMI_ModPlaceholderView implements AMI_iModFormView {
/* Constants */
// Tab state
const AMI_ModFormView::TAB_STATE_ACTIVE =  'active';
// Tab state
const AMI_ModFormView::TAB_STATE_COMMON =  'normal';
// Tab state
const AMI_ModFormView::TAB_STATE_DISABLED =  'disabled';
/* Properties */
// Form default elements template (placeholders)
protected array $aPlaceholders = array( '#form', 'public', 'id_dataset', 'id_page', 'id_cat', 'ext_custom_fields_addon', 'date_created', 'header', 'ext_adv', 'ext_image', 'ext_tags', 'ext_relations', '#ext_custom_fields_top', 'ext_custom_fields_top', '#default_tabset', '#announce_tab', 'announce', 'announce_tab', '#body_tab', 'body', 'body_tab', '#ext_custom_fields_tab', 'ext_custom_fields_tab', '#options_tab', 'disable_comments', 'sublink', 'html_title', 'html_keywords', 'html_description', 'og_image', 'details_noindex', '#ext_rating_values' ,'ext_rating_values', 'options_tab', 'default_tabset', '#ext_custom_fields_bottom', 'ext_custom_fields_bottom', 'form' );
// Placeholders custom data array.
protected array $aPlaceholdersData = array();
// View type
protected string $viewType = 'form';
/* Inherited Properties */
// Locale
protected AMI_View::$aLocale = array();
// Scope
protected AMI_View::$aScope = array();
// Locale file name
protected AMI_View::$localeFileName = '';
// Model
protected AMI_View::$oModel = null;
// Template block name
protected AMI_View::$tplBlockName = '';
// Template file name
protected AMI_View::$tplFileName = '';
/* Methods */
// Constructor.
public __construct ( ) returns AMI_ModFormView;
// Add new field into fields array.
public addField ( $aField ) returns AMI_ModFormView;
// Add fields section.
public addSection ( string $name, [ string $position = '' ], [ string|array $displayByAction = NULL ] ) returns false|AMI_ModFormView;
// Add a tab to the tab container. See AMI_ModFormView::addTabContainer() for usage example.
public addTab ( string $name, string $container, [ string $state = self::TAB_STATE_COMMON ], [ string $position = '' ], [ string $displayByAction = NULL ] ) returns AMI_ModFormView;
// Add a tab container on the form.
public addTabContainer ( string $name, [ string $position = '' ] ) returns AMI_ModFormView;
// Merges specified template with current one. New sets will be added, exisiting sets will be overwritten.
public addTemplate ( string $path, [ string $placeholderName = null ], [ $aLocale = null ] ) returns AMI_ModFormView;
// Drop field from fields array.
public dropField ( string $fieldName ) returns AMI_ModFormView;
// Drop the tab from the tab container.
public dropTab ( string $name, [ string $container = '' ] ) returns AMI_ModFormView;
// Returns view data.
public get ( ) returns string;
// Allows change field at displaying form.
public getFieldScope ( mixed &$aField ) returns void;
// Initialize fields.
public init ( ) returns AMI_View;
// Set field data to render field.
public setFieldData ( string $name, mixed $data ) returns AMI_ModFormView;
// Setting up model item object.
/* Inherited Methods */
// Constructor.
public AMI_ModPlaceholderView::__construct ( ) returns AMI_ModPlaceholderView;
// Add new field placeholders into placeholder list using AMI_ModPlaceholderView::putPlaceholder() without sections.
// Puts placeholder into required position.
public AMI_ModPlaceholderView::putPlaceholder ( string $name, [ string $positions = '' ], [ bool $isSection = false ] ) returns bool|int;
// Constructor.
public AMI_View::__construct ( ) returns AMI_View;
// Adds locale.
public AMI_View::addLocale ( $aLocale, [ bool $doOverwrite = true ] ) returns AMI_View;
// Adds script code.
public AMI_View::addScriptCode ( string $code ) returns AMI_View;
// Adds script file.
public AMI_View::addScriptFile ( string $file ) returns AMI_View;
// Returns view data.
public AMI_View::get ( ) returns mixed;
// Initialize, processing after setting model.
public AMI_View::init ( ) returns AMI_View;
// Adds locale from resource.
public AMI_View::setModel ( mixed $oModel, [ $aLocale = array() ], string $path ) returns AMI_View;
// Set module id.
public AMI_View::setModId ( string $modId ) returns void;
// Sets view scope.
public AMI_View::setScope ( $aScope ) returns AMI_View;
protected AMI_View::addOpenGraphTags ( $header, $description, [ $image = '' ] ) returns void;
// Returns module id.
protected AMI_View::getModId ( ) returns string;
// Returns module specific locale path.
protected AMI_View::getModLocalePath ( ) returns string;
// Returns prepared view scope.
protected AMI_View::getScope ( string $type, [ $aScope = array() ] ) returns array;
// Returns template object.
protected AMI_View::getTemplate ( ) returns AMI_iTemplate;
// Parses block template and returns the result as a string.
protected AMI_View::parse ( string $setName, [ $aScope = array() ] ) returns string;
// Sets up model object.
protected AMI_View::_setModel ( mixed $oModel ) returns AMI_View;
}
Tags:
abstract
since 5.12.0

• Class Constants

TAB_STATE_ACTIVE

Tab state

TAB_STATE_COMMON

Tab state

TAB_STATE_DISABLED

Tab state

• Class Properies

protected array $aPlaceholders

Form default elements template (placeholders)

protected array $aPlaceholdersData

Placeholders custom data array.

protected string $viewType

View type

• Class Methods

// Add new field into fields array.
public addField ( $aField ) returns AMI_ModFormView;
  • array $aField
    Field structure

Implementation of: AMI_iModFormView::addField().

Field structure is array having following data:
  • name - form field name;
  • type - field type: input|checkbox|textarea|hidden|select|radio|datetime|date, 'input' by default;
  • attributes - custom attributes (array, optional);
  • default_checked - default checkbox state (bool, optional);
  • rows - textarea tag "rows" attribute value (int, optional);
  • cols - textarea tag "cols" attribute value (int, optional);
  • data - select/radio tag options data (array, optional).
  • display_by_action - string/array to specify corresponding actions for field to display (edit, new, etc...) (since 5.12.8)

Example:
  •  // AmiSample_FormViewAdm
  •  public function init(){
  •      parent::init();
  •  
  •      // Common form fields {
  •  
  •      // Item id
  •      $this->addField(array('name' => 'id''type' => 'hidden'));
  •      // Form action - save item
  •      $this->addField(array('name' => 'mod_action''value' => 'form_save''type' => 'hidden'));
  •  
  •      // } Common form fields
  •  
  •      $this->addField(array('name' => 'nickname')'attributes' => array('readonly' => 'readonly'));
  •      $this->addField(array('name' => 'birth''type' => 'date'));
  •      // only after element create
  •      $this->addField(array('name' => 'creation_date''type' => 'date''display_by_action' => 'edit'));
  •  }
  Example:
  •  // Somewhere in AMI_ModFormViewAdm child
  •  public function init(){
  •      parent::init();
  •  
  •      // ...
  •  
  •      // <input type="text" name="text_field" ... />
  •      $this->addField(array('name' => 'text_field');
  •  
  •      // <input type="checkbox" name="checkbox" checked="checked" />
  •      // checked by default
  •      $this->addField(array('name' => 'checkbox_field''type' => 'checkbox''default_checked' => true));
  •  
  •      // <textarea name="textarea_field" ... >...</textarea>
  •      $this->addField(array('name' => 'textarea_field''type' => 'textarea''rows' => 10'cols' => 20));
  •  
  •      // <input type="hidden" name="hidden_field" ... />
  •      $this->addField(array('name' => 'hidden_field''type' => 'hidden'));
  •  
  •      // <select name="select_field"> ... </select>
  •      $this->addField(
  •          array(
  •              'name' => 'select_field',
  •              'type' => 'select',
  •              'data' => array(
  •                  // <option value="1">%%localized_caption%%</option> // %%localized_caption%% from locale resource
  •                  array('id' => '1''caption' => 'localized_caption'),
  •                  // <option value="0">direct_option_caption</option> // direct caption
  •                  array('id' => '0''name' => 'direct_option_caption')
  •              )
  •          )
  •      );
  •  
  •      // <radio name="radio_field"> ... </select>
  •      $this->addField(
  •          array(
  •              'name' => 'radio_field',
  •              'type' => 'select',
  •              'data' => array(
  •                  // <option value="0">%%localized_caption%%</option> // %%localized_caption%%from locale resource
  •                  array('id' => '0''caption' => 'localized_caption'),
  •                  // <option value="1">direct_option_caption</option> // direct caption
  •                  array('id' => '1''name' => 'direct_option_caption')
  •              )
  •          )
  •      );
  •  
  •      // text field for date with calendar popup control, separate text field for time
  •      $this->addField(array('name' => 'datetime_field''type' => 'datetime'));
  •  
  •      // text field for date with calendar popup control
  •      $this->addField(array('name' => 'date_field''type' => 'date'));
  •  
  •      // visual editor field
  •      $this->addField(
  •          array(
  •              'name' => 'about',                           // Field name
  •              'type' => 'htmleditor',                      // Field type
  •              'cols' => 80,                                // Number of columns
  •              'rows' => 10,                                // Number of rows
  •              'modes' => array('editor''bb''textarea'// Supported modes
  •          )
  •      );
  •  }
// Add fields section.
public addSection ( string $name, [ string $position = '' ], [ string|array $displayByAction = NULL ] ) returns false|AMI_ModFormView;
  • string $name
    Section name.
  • string $position
    Section placeholder position.
  • string|array $displayByAction
    String/array to specify corresponding actions for tab to display (edit, new, etc...).
// Add a tab to the tab container. See AMI_ModFormView::addTabContainer() for usage example.
public addTab ( string $name, string $container, [ string $state = self::TAB_STATE_COMMON ], [ string $position = '' ], [ string $displayByAction = NULL ] ) returns AMI_ModFormView;
  • string $name
    Tab name
  • string $container
    Container name
  • string $state
    State of the tab: AMI_ModFormView::TAB_STATE_COMMON, AMI_ModFormView::TAB_STATE_ACTIVE or AMI_ModFormView::TAB_STATE_DISABLED
  • string $position
    Tab placeholder position, before|after locations are supported
  • string $displayByAction
    String/array to specify corresponding actions for tab to display (edit, new, etc...)
Tags:
since 5.12.4
// Add a tab container on the form.
public addTabContainer ( string $name, [ string $position = '' ] ) returns AMI_ModFormView;
  • string $name
    Name of the container
  • string $position
    Container placeholder position
  Example:
  •  // Somewhere in AMI_ModFormViewAdm child
  •  public function init(){
  •      parent::init();
  •  
  •      // ...
  •  
  •      // Add new tab container
  •      $this->addTabContainer('tabset1');
  •  
  •      // Add tabs
  •      $this->addTab('tab1''tabset1''active');
  •      $this->addTab('tab2''tabset1');
  •  
  •      // Add a field to the first tab
  •      $this->addField(array('name' => 'about''type' => 'htmleditor''cols' => 80'rows' => 10'position' => 'tab1.end'));
  •  
  •      // Add a field to the second tab
  •      $this->addField(array('name' => 'birth''type' => 'date''position' => 'tab2.end'));
  •  
  •      // ...
  •  
  •  }
Tags:
see AMI_ModFormView::addTab()
since 5.12.4
// Merges specified template with current one. New sets will be added, exisiting sets will be overwritten.
public addTemplate ( string $path, [ string $placeholderName = null ], [ $aLocale = null ] ) returns AMI_ModFormView;
  • string $path
    Template path
  • string $placeholderName
    Custom template for specific placeholder ( optional )
  • array $aLocale
    Section template locale
Tags:
since 5.12.4
// Drop field from fields array.
public dropField ( string $fieldName ) returns AMI_ModFormView;
  • string $fieldName
    Field name
// Drop the tab from the tab container.
public dropTab ( string $name, [ string $container = '' ] ) returns AMI_ModFormView;
  • string $name
    Tab name
  • string $container
    Container name
// Returns view data.
public get ( ) returns string;
// Allows change field at displaying form.
public getFieldScope ( mixed &$aField ) returns void;
// Set field data to render field.
public setFieldData ( string $name, mixed $data ) returns AMI_ModFormView;
  • string $name
    Field name
  • mixed $data
    Field data
Tags:
since 6.0.4
// Setting up model item object.