/** * * @param GridField $gridField * @return string - HTML */ public function getHTMLFragments($gridField) { $searchState = $gridField->State->GridFieldSearchRelation; $dataClass = $gridField->getList()->dataClass(); $forTemplate = new ArrayData(array()); $forTemplate->Fields = new ArrayList(); $searchFields = $this->getSearchFields() ? $this->getSearchFields() : $this->scaffoldSearchFields($dataClass); $value = $this->findSingleEntry($gridField, $searchFields, $searchState, $dataClass); $searchField = new TextField('gridfield_relationsearch', _t('GridField.RelationSearch', "Relation search"), $value); // Apparently the data-* needs to be double qouted for the jQuery.meta data plugin $searchField->setAttribute('data-search-url', '\'' . Controller::join_links($gridField->Link('search') . '\'')); $searchField->setAttribute('placeholder', $this->getPlaceholderText($dataClass)); $searchField->addExtraClass('relation-search no-change-track'); $findAction = new GridField_FormAction($gridField, 'gridfield_relationfind', _t('GridField.Find', "Find"), 'find', 'find'); $findAction->setAttribute('data-icon', 'relationfind'); $addAction = new GridField_FormAction($gridField, 'gridfield_relationadd', _t('GridField.LinkExisting', "Link Existing"), 'addto', 'addto'); $addAction->setAttribute('data-icon', 'chain--plus'); // If an object is not found, disable the action if (!is_int($gridField->State->GridFieldAddRelation)) { $addAction->setReadonly(true); } $forTemplate->Fields->push($searchField); $forTemplate->Fields->push($findAction); $forTemplate->Fields->push($addAction); return array($this->targetFragment => $forTemplate->renderWith($this->itemClass)); }
/** * * @param GridField $gridField * @return string - HTML */ public function getHTMLFragments($gridField) { $dataClass = $gridField->getList()->dataClass(); $forTemplate = new ArrayData(array()); $forTemplate->Fields = new ArrayList(); $searchField = new TextField('gridfield_relationsearch', _t('GridField.RelationSearch', "Relation search")); $searchField->setAttribute('data-search-url', Controller::join_links($gridField->Link('search'))); $searchField->setAttribute('placeholder', $this->getPlaceholderText($dataClass)); $searchField->addExtraClass('relation-search no-change-track'); $findAction = new GridField_FormAction($gridField, 'gridfield_relationfind', _t('GridField.Find', "Find"), 'find', 'find'); $findAction->setAttribute('data-icon', 'relationfind'); $addAction = new GridField_FormAction($gridField, 'gridfield_relationadd', _t('GridField.LinkExisting', "Link Existing"), 'addto', 'addto'); $addAction->setAttribute('data-icon', 'chain--plus'); // If an object is not found, disable the action if (!is_int($gridField->State->GridFieldAddRelation(null))) { $addAction->setReadonly(true); } $forTemplate->Fields->push($searchField); $forTemplate->Fields->push($findAction); $forTemplate->Fields->push($addAction); return array($this->targetFragment => $forTemplate->renderWith($this->itemClass)); }