PHP code example of primoz2500 / hasoneautocompletefield

1. Go to this page and download the library: Download primoz2500/hasoneautocompletefield library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

primoz2500 / hasoneautocompletefield example snippets




use SilverStripe\CMS\Model\SiteTree;
use NathanCox\HasOneAutocompleteField\Forms\HasOneAutocompleteField;

class Page extends SiteTree
{
    private static $db = [];

    private static $has_one = [
        'LinkedPage' => 'Page'
    ];

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        $fields->addFieldToTab('Root.Content', $pageField = HasOneAutocompleteField::create('LinkedPageID', 'Linked Page', 'Page', 'Title'));
        $pageField->setSearchFields(array('Title', 'Content'));
        $pageField->enableClearButton();

        return $fields;
    }
}