/** * Create an uri for an entity. * * @param $entity * The entity to get the path from. * * @return * A string containing the path of the entity, NULL if the entity has no * uri of its own. */ function createPath($entity) { // Create the URI for the entity. $uri = entity_uri($this->plugin['entity_type'], $entity); $options = array(); // Handle multilingual sites. if (isset($entity->language) && $entity->language != LANGUAGE_NONE && drupal_multilingual() && language_negotiation_get_any(LOCALE_LANGUAGE_NEGOTIATION_URL)) { $languages = language_list('enabled'); // Only use enabled languages. $languages = $languages[1]; if ($languages && isset($languages[$entity->language])) { $options['language'] = $languages[$entity->language]; } } // Process the uri with the insert pluing. $path = linkit_get_insert_plugin_processed_path($this->profile, $uri['path'], $options); return $path; }
/** * Overrides LinkitSearchPluginEntity::createPath(). * * If 'Direct download' is enabled, make the link point to the file entity * download endpoint. */ function createPath($entity) { $url_type = isset($this->conf['url_type']) ? $this->conf['url_type'] : $this->getDefaultUrlType(); // We can only support the download type if we have version 2.x of the file_entity module. if ($url_type == LINKIT_FILE_URL_TYPE_DOWNLOAD && !(module_exists('file_entity') && function_exists('file_entity_download_uri'))) { $url_type = $this->getDefaultUrlType(); } switch ($url_type) { case LINKIT_FILE_URL_TYPE_DIRECT: // Check if this is a local file. $wrapper = file_stream_wrapper_get_instance_by_uri($entity->uri); if ($wrapper instanceof DrupalLocalStreamWrapper) { // Create a relative URL to the local file. // See https://www.drupal.org/node/837794. $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($entity->uri); } else { $path = file_create_url($entity->uri); } // Process the uri with the insert plugin. return linkit_get_insert_plugin_processed_path($this->profile, $path, array('language' => (object) array('language' => FALSE))); case LINKIT_FILE_URL_TYPE_DOWNLOAD: $uri = file_entity_download_uri($entity); // Hack for LINKIT_URL_METHOD_RAW, which won't include the options that // we pass to linkit_get_insert_plugin_processed_path(). if (isset($uri['options']['query']['token']) && $this->profile->data['insert_plugin']['url_method'] == LINKIT_URL_METHOD_RAW) { return $uri['path'] . '?token=' . rawurlencode($uri['options']['query']['token']); } // Process the uri with the insert plugin. return linkit_get_insert_plugin_processed_path($this->profile, $uri['path'], $uri['options']); case LINKIT_FILE_URL_TYPE_ENTITY: // Pass back to the parent if the user wants entity urls. return parent::createPath($entity); } }