Developer Guide / April 4, 2017

Field System - Search Object

When a registered field is called via Property Factory to build its markup for search field display purposes, the field system will search for the entry value of objects.search in the field configuration array and when found, the entry value will be treated as the class name when building the search field object.

The search object can utilize VTCore_Property_Models_Search if the search field is simple and only going to be a textfield ($context.element.bstext) or taxonomy terms select box ($context.element.wpterms).

For a more customized and complex search form field, it is suggested to extend VTCore_Bootstrap_Form_Base directly.

The search element follow the rules of VTCore_Html_Form / VTCore_Bootstrap_Form_Base when building the markup via object.

Example of a simple search object using taxonomy select field

 

/**
 * Class for building the property status
 * search field
 *
 * @author jason.xie@victheme.com
 *
 */
class VTCore_Property_Form_Search_Status
extends VTCore_Property_Models_Search {

  protected $context = array(
    'type' => 'div',
    'attributes' => array(
      'class' => array(
        'property-search-group',
        'property-search-status',
      ),
    ),
    'queryid' => '',

    // This is related to pre_get_posts and serve as the query key.
    'searchkey' => '_property_status',

    // Inform the parent class that we are building
    // A taxonomy select form, use bstext if you want
    // a text field instead.
    'element' => 'wpterms',

    // Inform the parent class that the select field
    // need terms from taxonomy property_status
    'taxonomies' => array('property_status'),
  );
}

 

Example on building a complex search form field

/**
 * Class for building the property landsize
 * search field
 *
 * @author jason.xie@victheme.com
 *
 */
class VTCore_Property_Form_Search_LandSize
extends VTCore_Bootstrap_Form_Base {

  protected $context = array(
    'type' => 'div',
    'attributes' => array(
      'class' => array(
        'property-search-group',
        'property-search-landsize',
      ),
    ),
    'queryid' => '',
  );


  /**
   * Overriding Parent Method
   * @see VTCore_Bootstrap_Form_Base::assignContext()
   */
  protected function assignContext() {

    // We need larger column for this kind of search form
    // This is configured via backend
    if ($this->getContext('alignment') == 'horizontal') {
      $this->addContext('grids', array(
        'columns' => array(
          'mobile' => 12,
          'tablet' => 8,
          'small' => 8,
          'large' => 8,
        )
      ));
    }

    parent::assignContext();
  }

  /**
   * Overriding Parent Method
   * @see VTCore_Html_Base::buildElement()
   */
  public function buildElement() {

    // Call parent method
    parent::buildElement();

    // the dimension field default grid size
    $dimensionGrids = array(
      'columns' => array(
        'mobile' => 12,
        'tablet' => 4,
        'small' => 4,
        'large' => 4,
      ),
    );

    // The default grid size
    $grids = array(
      'columns' => array(
        'mobile' => 12,
        'tablet' => 6,
        'small' => 6,
        'large' => 6,
      ),
    );

    // Mutate the field element grid size when 2 field is visible
    if ($this->getContext('visibility.dimension')) {
      $grids = array(
        'columns' => array(
          'mobile' => 12,
          'tablet' => 4,
          'small' => 4,
          'large' => 4,
        ),
      );
    }

    // Build a grid wrapper if both landsize and dimension 
    // is visible, this is for inline form markup
    if ($this->getContext('visibility.landsize') || $this->getContext('visibility.dimension')) {

      $this->addChildren(new VTCore_Bootstrap_Grid_BsRow());

      if ($this->getContext('visibility.label')) {
        $this
          ->lastChild()
          ->addChildren(new VTCore_Bootstrap_Grid_BsColumn(array(
            'type' => 'div',
            'grids' => array(
              'columns' => array(
                'mobile' => 12,
                'tablet' => 12,
                'small' => 12,
                'large' => 12,
              ),
            ),
          )))
          ->lastChild()
          ->addChildren(new VTCore_Form_Label(array(
            'text' => $this->getContext('search.label'),
            'attributes' => array(
              'class' => array('form-group-label'),
            ),
          )));
      }
    }

    // User configure to display the landsize text field
    if ($this->getContext('visibility.landsize')) {
      $this
        ->lastChild()
        ->addChildren(new VTCore_Bootstrap_Form_BsText(array(
          'text' => $this->getContext('search.settings.minsize.context.value'),
          'name' => $this->getContext('queryid') . '_property_landsize_minimum',
          'grids' => $grids
        )))
        ->addChildren(new VTCore_Bootstrap_Form_BsText(array(
          'text' => $this->getContext('search.settings.maxsize.context.value'),
          'name' => $this->getContext('queryid') . '_property_landsize_maximum',
          'grids' => $grids
        )));
    }

    // User configured to build the dimension settings
    if ($this->getContext('visibility.dimension')) {
      $this
        ->lastChild()
        ->addChildren(new VTCore_Wordpress_Form_WpTerms(array(
          'text' => $this->getContext('search.settings.dimension.context.value'),
          'name' => $this->getContext('queryid') . '_property_dimension[]',
          'taxonomies' => array('property_dimension'),
          'grids' => $dimensionGrids,
        )));
    }
  }

}

 

Related Product

WordPress Property Real Estate Plugin

VT Property is a WordPress plugin for Real estate and Properties sites. You can have unlimited attributes for the properties and create multiple agents as user. Available Features Ajax search form Custom property icon Different property attributes Different property types Visual composer ready Property marker within maps Custom marker upload...
View Product

Related Documentation

Entity System - Property Factory

Entity System - Property Factory

What is Property Entity Factory? Property entity factory is the PHP class wrapper for building a property entity object based on data from a property post data. The class will build all relevant type entity, field entities and attribute entities related to a single post entry. I...
Creating agents listing template

Creating agents listing template

If there is no valid agents listing page then the plugin will use author.php template which will display all author posts instead of listing of agents. Therefore it is strongly suggested to create a custom agents listing template in your theme. Step One – Locate theme...
Field System - Display Object

Field System - Display Object

/** * Class for building the field status * * @author jason.xie@victheme.com * */ class VTCore_Property_Element_Status extends VTCore_Property_Models_Element { /** * Define the default context array * The context will be merged with user supplied context ...
Creating property archive template

Creating property archive template

It is recommended to create a separate archive template for property rather than using theme default archive.php or index.php. Step One – Locate theme file You will need to locate theme archive.php or index.php which usually located in the root folder of your theme. Step...
Entity System - Property Type

Entity System - Property Type

What is Type Entity? Type entity is a PHP class for managing property type entity Create Revise Update and Delete process. The purpose of this class is to act as the general gateway object for other to use. What is property type? Property type is actually a Taxonomy with Terms t...
Field System - Search Query Vars

Field System - Search Query Vars

When a custom property field is marked as allowed for searching there are couple of extra steps needed to register the query variables so it will be eligible when WP_Query is processing the actual query. Step One – Register the searched variable key When Building the Prope...
Creating property single template

Creating property single template

It is recommended to create a separate single page template for property rather than using theme default page.php or single.php or index.php. Step One – Locate theme file You will need to locate theme page.php or single.php or index.php which usually located in the root f...
Entity System - Property Field

Entity System - Property Field

What is Field Entity? Field entity is a PHP class for wrapping all operations such as creating, updating and disabling the property field system. It is recommended to use the class object when trying to manipulate the field system as many logic and hooks is will be invoked inside...
Field System - Field Hooks

Field System - Field Hooks

Property plugin Fields System is alterable via hooks : Hook Filter – vtcore_property_alter_fields This filter allows you to modify, remove or add fields into the field registration, It will be fired when VTCore_Property_Fields object is created Hook Action – vtcore_...
Field System - Configuration Array

Field System - Configuration Array

The Field System Array is designed to store field related information, the information will be used in various objects under different circumstances. Like for example the translation key will be used as the array key map when integrating field dynamic strings to WPML plugin for t...
Entity System - Property Attributes

Entity System - Property Attributes

What is Attributes Entity? Attributes entity object is a PHP class for managing the Property Attributes entry to a property type. It is recommended to use this class when need to alter a Property Attributes programatically only. What is property attributes? Property Attributes i...
Creating agents profile template

Creating agents profile template

If there is no valid agents profile page then the plugin will use author.php template which will display all author posts instead the agents profile page. Therefore you must create a custom agents profile template to display the author profile information. Step One – ...
Overriding Plugin Templates

Overriding Plugin Templates

You can override all templates found in victheme_property/templates folder by creating an new folder with this structure templates/property/ in the root of your theme. Then copy the templates files that you want to override from victheme_property/templates folder into the newly ...
Overriding plugin assets

Overriding plugin assets

You can override any of the VicTheme Property or VicTheme Agents or VicTheme Core plugins default CSS and Javascript assets by registering a new assets to replace the old assets. For example, to override the property-front.css which is bundled inside the property-front assets yo...
Video Documentation

Video Documentation

How To Create Agents How to create property attributes How to create and manage property type How to configure teaser element How to add video on property pag...