/**
  * The autocomplete callback function for the Linkit Entity plugin.
  *
  * @return
  *   An associative array whose values are an
  *   associative array containing:
  *   - title: A string to use as the search result label.
  *   - description: (optional) A string with additional information about the
  *     result item.
  *   - path: The URL to the item.
  *   - group: (optional) A string with the group name for the result item.
  *     Best practice is to use the plugin name as group name.
  *   - addClass: (optional) A string with classes to add to the result row.
  */
 function autocomplete_callback()
 {
     $matches = array();
     // Get the EntityFieldQuery instance.
     $this->getQueryInstance();
     // Add the search condition to the query object.
     $this->query->propertyCondition($this->entity_field_label, '%' . db_like($this->search_string) . '%', 'LIKE')->addTag('linkit_entity_autocomplete')->addTag('linkit_' . $this->plugin['entity_type'] . '_autocomplete');
     // Add access tag for the query.
     // There is also a runtime access check that uses entity_access().
     $this->query->addTag($this->plugin['entity_type'] . '_access');
     // Bundle check.
     if (isset($this->entity_key_bundle) && isset($this->conf['bundles'])) {
         if ($bundles = array_filter($this->conf['bundles'])) {
             $this->query->propertyCondition($this->entity_key_bundle, $bundles, 'IN');
         }
     }
     // Execute the query.
     $result = $this->query->execute();
     if (!isset($result[$this->plugin['entity_type']])) {
         return array();
     }
     $ids = array_keys($result[$this->plugin['entity_type']]);
     // Load all the entities with all the ids we got.
     $entities = entity_load($this->plugin['entity_type'], $ids);
     foreach ($entities as $entity) {
         // Check the access againt the definded entity access callback.
         if (entity_access('view', $this->plugin['entity_type'], $entity) === FALSE) {
             continue;
         }
         $matches[] = array('title' => $this->buildLabel($entity), 'description' => $this->buildDescription($entity), 'path' => $this->buildPath($entity), 'group' => $this->buildGroup($entity), 'addClass' => $this->buildRowClass($entity));
     }
     return $matches;
 }
Example #2
0
 function save($source = 'eContent')
 {
     global $user;
     // Fail if we don't know what record we're working with:
     if (!isset($_GET['id'])) {
         return false;
     }
     // Create a resource entry for the current ID if necessary (or find the
     // existing one):
     $resource = new Resource();
     $resource->record_id = $_GET['id'];
     $resource->source = $source;
     if (!$resource->find(true)) {
         $resource->insert();
     }
     // Parse apart the tags and save them in association with the resource:
     preg_match_all('/"[^"]*"|[^,]+/', $_REQUEST['tag'], $words);
     foreach ($words[0] as $tag) {
         $tag = trim(strtolower(str_replace('"', '', $tag)));
         $resource->addTag($tag, $user);
     }
     // Done -- report success:
     return true;
 }
Example #3
0
 function SaveTag()
 {
     $user = UserAccount::isLoggedIn();
     if ($user === false) {
         return json_encode(array('result' => 'Unauthorized'));
     }
     // Create a resource entry for the current ID if necessary (or find the
     // existing one):
     $resource = new Resource();
     $resource->record_id = $_GET['id'];
     $resource->source = $_REQUEST['source'];
     if (!$resource->find(true)) {
         $resource->insert();
     }
     // Parse apart the tags and save them in association with the resource:
     preg_match_all('/"[^"]*"|[^,]+/', $_REQUEST['tag'], $words);
     foreach ($words[0] as $tag) {
         $tag = trim(strtolower(str_replace('"', '', $tag)));
         $resource->addTag($tag, $user);
     }
     return json_encode(array('result' => 'Done'));
 }
Example #4
0
 /**
  * Save the tag information based on GET parameters.
  *
  * @param object $user User that is adding the tag.
  *
  * @return bool        True on success, false on failure.
  * @access public
  */
 public static function save($user)
 {
     // Fail if we don't know what record we're working with:
     if (!isset($_GET['id'])) {
         return false;
     }
     $db = ConnectionManager::connectToIndex();
     if (!($record = $db->getRecord($_GET['id']))) {
         return false;
     }
     // Create a resource entry for the current ID if necessary (or find the
     // existing one):
     $resource = new Resource();
     $resource->record_id = $_GET['id'];
     if (!$resource->find(true)) {
         $resource->insert();
     }
     // Parse apart the tags and save them in association with the resource:
     preg_match_all('/"[^"]*"|[^ ]+/', $_REQUEST['tag'], $words);
     foreach ($words[0] as $tag) {
         $tag = str_replace('"', '', $tag);
         $resource->addTag($tag, $user);
     }
     // Done -- report success:
     return true;
 }