To create a FLEXIcontent field (a form field in item form and frontend views)
- you simply create joomla plugins that extend
a. either the Joomla plugin class JPlugin
b. or the class FCField
and these plugin reside in path like:
List of the CLASS methods = (plugin events) triggered are:
Editing
{jb_brownbox}onDisplayField - editing HTML for item form
Viewing
Field value handling
Text-search / filtering for category view
Text-search / filtering for search view
Following there is code of an empty field example,
Field example
defined( '_JEXEC' ) or die( 'Restricted access' ); jimport('cms.plugin.plugin'); JLoader::register('FCField', JPATH_ADMINISTRATOR . '/components/com_flexicontent/helpers/fcfield/parentfield.php'); class plgFlexicontent_fieldsText extends FCField { // *********** // CONSTRUCTOR // *********** function plgFlexicontent_fieldsText( &$subject, $params ) { parent::__construct( $subject, $params ); JPlugin::loadLanguage('plg_flexicontent_fields_text', JPATH_ADMINISTRATOR); } // ******************************************* // DISPLAY methods, item form & frontend views // ******************************************* // Method to create field's HTML display for item form function onDisplayField(&$field, &$item) { // execute the code only if the field type match the plugin type if($field->field_type != 'text') return; $field->label = JText::_($field->label); // ... $field->html = '...'; } // Method to create field's HTML display for frontend views function onDisplayFieldValue(&$field, $item, $values=null, $prop='display') { // execute the code only if the field type match the plugin type if($field->field_type != 'text') return; $field->label = JText::_($field->label); //... $field->{$prop} = '...'; } // ************************************************************** // METHODS HANDLING before & after saving / deleting field events // ************************************************************** // Method to handle field's values before they are saved into the DB function onBeforeSaveField( &$field, &$post, &$file, &$item ) { // execute the code only if the field type match the plugin type if($field->field_type != 'text') return; if(!is_array($post) && !strlen($post)) return; // Make sure posted data is an array $post = !is_array($post) ? array($post) : $post; // Reformat the posted data $newpost = array(); foreach ($post as $n=>$v) { //... } $post = $newpost; } // Method to take any actions/cleanups needed after field's values are saved into the DB function onAfterSaveField( &$field, &$post, &$file, &$item ) { } // Method called just before the item is deleted to remove custom item data related to the field function onBeforeDeleteField(&$field, &$item) { } // ********************************* // CATEGORY/SEARCH FILTERING METHODS // ********************************* // Method to display a search filter for the advanced search view function onAdvSearchDisplayFilter(&$filter, $value='', $formName='searchForm') { if($filter->field_type != 'text') return; plgFlexicontent_fieldsText::onDisplayFilter($filter, $value, $formName); } // Method to display a category filter for the category view function onDisplayFilter(&$filter, $value='', $formName='adminForm') { // execute the code only if the field type match the plugin type if($filter->field_type != 'text') return; // ** some parameter shortcuts $label_filter = $filter->parameters->get( 'display_label_filter', 0 ) ; if ($label_filter == 2) $text_select = $filter->label; else $text_select = JText::_('FLEXI_ALL'); // ... $filter->html = '...'; } // Method to get the active filter result (an array of item ids matching field filter, or subquery returning item ids) // This is for content lists e.g. category view, and not for search view function getFiltered(&$filter, $value, $return_sql=true) { if ( !in_array($filter->field_type, self::$field_types) ) return; return FlexicontentFields::getFiltered($filter, $value, $return_sql); } // Method to get the active filter result (an array of item ids matching field filter, or subquery returning item ids) // This is for search view function getFilteredSearch(&$filter, $value, $return_sql=true) { if ( !in_array($filter->field_type, self::$field_types) ) return; $filter->isindexed = true; return FlexicontentFields::getFilteredSearch($filter, $value, $return_sql); } // ************************* // SEARCH / INDEXING METHODS // ************************* // Method to create (insert) advanced search index DB records for the field values function onIndexAdvSearch(&$field, &$post, &$item) { if ( !in_array($field->field_type, self::$field_types) ) return; if ( !$field->isadvsearch && !$field->isadvfilter ) return; // a. Each of the values of $values array will be added to the advanced search index as searchable text (column value) // b. Each of the indexes of $values will be added to the column 'value_id', // and it is meant for fields that we want to be filterable via a drop-down select // c. If $values is null then only the column 'value' will be added to the search index after retrieving // the column value from table 'flexicontent_fields_item_relations' for current field / item pair will be used // 'required_properties' is meant for multi-property fields, do not add to search index if any of these is empty // 'search_properties' contains property fields that should be added as text // 'properties_spacer' is the spacer for the 'search_properties' text // 'filter_func' is the filtering function to apply to the final text FlexicontentFields::onIndexAdvSearch($field, $post, $item, $required_properties=array(), $search_properties=array(), $properties_spacer=' ', $filter_func='strip_tags'); return true; } // Method to create basic search index (added as the property field->search) function onIndexSearch(&$field, &$post, &$item) { if ( !in_array($field->field_type, self::$field_types) ) return; if ( !$field->issearch ) return; // a. Each of the values of $values array will be added to the basic search index (one record per item) // b. If $values is null then the column value from table 'flexicontent_fields_item_relations' for current field / item pair will be used // 'required_properties' is meant for multi-property fields, do not add to search index if any of these is empty // 'search_properties' contains property fields that should be added as text // 'properties_spacer' is the spacer for the 'search_properties' text // 'filter_func' is the filtering function to apply to the final text FlexicontentFields::onIndexSearch($field, $post, $item, $required_properties=array(), $search_properties=array(), $properties_spacer=' ', $filter_func='strip_tags'); return true; } }