You are here

protected function RestfulEntityBase::getListForAutocomplete in RESTful 7

Return the values of the types tags, with the ID.

Return value

array Array with the found terms keys by the entity ID. ID. Otherwise, if the field allows auto-creating tags, the ID will be the term name, to indicate for client it is an unsaved term.

Throws

\Exception

See also

taxonomy_autocomplete()

1 call to RestfulEntityBase::getListForAutocomplete()
RestfulEntityBase::getList in plugins/restful/RestfulEntityBase.php
Get a list of entities.

File

plugins/restful/RestfulEntityBase.php, line 173
Contains RestfulEntityBase.

Class

RestfulEntityBase
An abstract implementation of RestfulEntityInterface.

Code

protected function getListForAutocomplete() {
  $entity_info = $this
    ->getEntityInfo();
  if (empty($entity_info['entity keys']['label'])) {

    // Entity is invalid for autocomplete, as it doesn't have a "label"
    // property.
    $params = array(
      '@entity' => $this
        ->getEntityType(),
    );
    throw new \Exception(format_string('Cannot autocomplete @entity as it does not have a "label" property defined.', $params));
  }
  $request = $this
    ->getRequest();
  if (empty($request['autocomplete']['string'])) {

    // Empty string.
    return array();
  }
  $result = $this
    ->getQueryResultForAutocomplete();
  $return = array();
  foreach ($result as $entity_id => $label) {
    $return[$entity_id] = check_plain($label);
  }
  return $return;
}