WordPress Property Real Estate Plugin

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 [email protected]
 *
 */
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 [email protected]
 *
 */
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,
        )));
    }
  }

}