initial commit of starter install drupal 7

This commit is contained in:
Bachir Soussi Chiadmi
2015-02-21 17:21:40 +01:00
commit eeba51cea6
6113 changed files with 1249218 additions and 0 deletions
@@ -0,0 +1,67 @@
<?php
/**
* @file
* Contains the Linkit profile export UI integration code.
*/
/**
* Linktit profile export UI class handler for Views UI.
*/
class linkit_profiles extends ctools_export_ui {
/**
* @TODO: Can we call parent:list_build_row and then just add linkit specific
* columns?
*/
function list_build_row($item, &$form_state, $operations) {
// Set up sorting
$name = $item->{$this->plugin['export']['key']};
$schema = ctools_export_get_schema($this->plugin['schema']);
// Note: $item->{$schema['export']['export type string']} should have already been set up by export.inc so
// we can use it safely.
switch ($form_state['values']['order']) {
case 'disabled':
$this->sorts[$name] = empty($item->disabled) . $name;
break;
case 'title':
$this->sorts[$name] = $item->{$this->plugin['export']['admin_title']};
break;
case 'name':
$this->sorts[$name] = $name;
break;
case 'storage':
$this->sorts[$name] = $item->{$schema['export']['export type string']} . $name;
break;
}
$this->rows[$name]['data'] = array();
$this->rows[$name]['class'] = !empty($item->disabled) ? array('ctools-export-ui-disabled') : array('ctools-export-ui-enabled');
// If we have an admin title, make it the first row.
if (!empty($this->plugin['export']['admin_title'])) {
$this->rows[$name]['data'][] = array('data' => check_plain($item->{$this->plugin['export']['admin_title']}), 'class' => array('ctools-export-ui-title'));
}
// Profile type.
$this->rows[$name]['data'][] = array('data' => linkit_get_profile_type($item->profile_type), 'class' => array('linkit-export-ui-profile-type'));
// Storage.
$this->rows[$name]['data'][] = array('data' => check_plain($item->{$schema['export']['export type string']}), 'class' => array('ctools-export-ui-storage'));
// Operations.
$ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
$this->rows[$name]['data'][] = array('data' => $ops, 'class' => array('ctools-export-ui-operations'));
// Add an automatic mouseover of the description if one exists.
$this->rows[$name]['title'] = $item->{$this->plugin['export']['admin_description']};
}
function list_table_header() {
$header = array();
$header[] = array('data' => t('Title'), 'class' => array('ctools-export-ui-title'));
$header[] = array('data' => t('Profile type'), 'class' => array('ctools-export-ui-profile-type'));
$header[] = array('data' => t('Storage'), 'class' => array('ctools-export-ui-storage'));
$header[] = array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations'));
return $header;
}
}
@@ -0,0 +1,501 @@
<?php
/**
* @file
* Ctools export ui plugin to handle Linkit profiles.
*/
$plugin = array(
'schema' => 'linkit_profiles',
'access' => 'administer linkit',
'menu' => array(
'menu prefix' => 'admin/config/content',
'menu item' => 'linkit',
'menu title' => 'Linkit Profiles',
'menu description' => t('Manage Linkit profiles.'),
),
'title singular' => t('Linkit profile'),
'title plural' => t('Linkit profiles'),
'title singular proper' => t('Linkit profile'),
'title plural proper' => t('Linkit profiles'),
'handler' => 'linkit_profiles',
);
/**
* Linkit profile settings form.
*
* @param $form
* A nested array of form elements that comprise the form.
* @param $form_state
* An associative array containing the current state of the form.
*/
function linkit_profiles_form(&$form, &$form_state) {
$profile = $form_state['item'];
// Set data as a tree.
$form['data'] = array(
'#tree' => TRUE,
'#type' => 'vertical_tabs',
);
// Append profile type settings to the profile form.
_linkit_build_profile_type_form_fields($form, $profile);
// Append search plugin form element to the profile form.
_linkit_build_search_plugin_form_fields($form, $profile);
// Append insert plugin form element to the profile form.
_linkit_build_insert_plugin_form_fields($form, $profile);
// Append attribute plugin form element to the profile form.
_linkit_build_attribute_plugin_form_fields($form, $profile);
// Append IMCE plugin form element to the profile form.
if (module_exists('imce')) {
_linkit_build_imce_form_fields($form, $profile);
}
// Append autocomplete (BAC) form element to the profile form.
_linkit_build_autocomplete_form_fields($form, $profile);
}
/**
* Linkit profile validate callback.
*
* @see linkit_profiles_form()
*/
function linkit_profiles_form_validate(&$form, &$form_state) {
// If the profile type is field, then insert plugin is required.
if ($form_state['values']['profile_type'] == LINKIT_PROFILE_TYPE_FIELD
&& empty($form_state['values']['data']['insert_plugin']['plugin'])) {
form_set_error('data][insert_plugin][plugin', t('You have to select a insert plugin for profiles used with fields.'));
}
}
/**
* Linkit profile submit callback.
*
* @see linkit_profiles_form()
*/
function linkit_profiles_form_submit(&$form, &$form_state) {
// Unset some variables used by "field profiles" to make it clean.
if ($form_state['values']['profile_type'] == LINKIT_PROFILE_TYPE_EDITOR) {
unset($form_state['values']['data']['insert_plugin']['plugin']);
}
// Unset some variables used by "editor profiles" to make it clean.
if ($form_state['values']['profile_type'] == LINKIT_PROFILE_TYPE_FIELD) {
unset($form_state['values']['data']['text_formats']);
}
// Unset active tab state, we dont need to save this.
unset($form_state['values']['data']['data__active_tab']);
}
/**
* Append profile type form element to the profile form.
*
* @param LinkitProfile $profile
* A profile object contains all settings for the profile.
*
* @see linkit_profiles_form()
*/
function _linkit_build_profile_type_form_fields(&$form, LinkitProfile $profile) {
$form['data']['profile_type'] = array(
'#type' => 'fieldset',
'#title' => t('Profile type'),
'#description' => t(''),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => FALSE,
);
$form['data']['profile_type']['profile_type'] = array(
'#title' => t("This profile will be used with"),
'#type' => 'radios',
'#title_display' => 'before',
'#options' => array(
LINKIT_PROFILE_TYPE_EDITOR => t('Editors'),
LINKIT_PROFILE_TYPE_FIELD => t('Fields'),
),
LINKIT_PROFILE_TYPE_EDITOR => array(
'#description' => t('This profile will be used with editors like CKeditor or TinyMCE.'),
),
LINKIT_PROFILE_TYPE_FIELD => array(
'#description' => t('This profile will be used with fields that do not have any editors.'),
),
'#default_value' => isset($profile->profile_type) ? $profile->profile_type : 'editor',
'#required' => TRUE,
'#parents' => array('profile_type'),
);
$formats = array();
foreach(filter_formats() as $format) {
$formats[$format->format] = $format->name;
}
$form['data']['profile_type']['text_formats'] = array(
'#type' => 'checkboxes',
'#title' => t('Attach this profile to one or more text formats'),
'#options' => $formats,
'#empty_option' => t('- Select one or more text format- '),
'#default_value' => isset($profile->data['text_formats'])
? $profile->data['text_formats'] : array(),
'#description' => t('.'),
'#states' => array(
'visible' => array(
// While waiting for https://drupal.org/node/879580 to be commited, we
// have to convert the constant to a string.
'input[name="profile_type"]' => array('value' => (string) LINKIT_PROFILE_TYPE_EDITOR),
),
),
'#parents' => array('data', 'text_formats'),
);
}
/**
* Append search plugin form element to the profile form.
*
* @param LinkitProfile $profile
* A profile object contains all settings for the profile.
*
* @see linkit_profiles_form()
*/
function _linkit_build_search_plugin_form_fields(&$form, LinkitProfile $profile) {
// Load all search plugins.
$search_plugins = linkit_search_plugin_load_all();
$form['data']['search_plugins_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Search plugins'),
'#description' => t('Linkit is all about the search plugins. They define what content Linkit will present in the autocomplete search field.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => FALSE,
);
$form['data']['search_plugins_fieldset']['search_plugins'] = array(
'#markup' => '',
'#tree' => TRUE,
'#parents' => array('data', 'search_plugins'),
'#theme' => 'linkit_plugin_form_table',
);
$form['data']['search_plugins_fieldset']['search_plugins_settings'] = array(
'#markup' => '',
'#tree' => TRUE,
'#parents' => array('data'),
);
// Used to store plugin form elements temporary so we can use this to sort by
// weight later.
$tmp = array();
foreach ($search_plugins AS $name => $plugin_definition) {
// Get a plugin instance.
$plugin = LinkitSearchPlugin::factory($plugin_definition, $profile);
$tmp[$name]['name'] = array('#markup' => $plugin->ui_title());
$tmp[$name]['description'] = array('#markup' => $plugin->ui_description());
$tmp[$name]['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable @title', array('@title' => $plugin->ui_title())),
'#title_display' => 'invisible',
'#default_value' => isset($profile->data['search_plugins'][$name]['enabled'])
? $profile->data['search_plugins'][$name]['enabled'] : FALSE,
);
$tmp[$name]['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight for @title', array('@title' => $plugin->ui_title())),
'#title_display' => 'invisible',
'#default_value' => isset($profile->data['search_plugins'][$name]['weight'])
? $profile->data['search_plugins'][$name]['weight'] : '',
);
// Append the search plugin specific settings.
$plugin_specific_settings = $plugin->buildSettingsForm();
if ($plugin_specific_settings) {
// Add the handler settings form to the generic.
$form['data']['search_plugins_fieldset']['search_plugins_settings'] += $plugin_specific_settings;
}
}
// Sort by weight.
uasort($tmp, '_linkit_sort_plugins_by_weight_default_value');
foreach ($tmp AS $name => $element) {
$form['data']['search_plugins_fieldset']['search_plugins'][$name] = $element;
}
}
/**
* Append insert plugin form element to the profile form.
*
* @param LinkitProfile $profile
* A profile object contains all settings for the profile.
*
* @see linkit_profiles_form()
*
* @TODO: Insert pluings should only be used when dealing with fields as it
* makes no sence to have them when using a wysiwyg editor.
*/
function _linkit_build_insert_plugin_form_fields(&$form, LinkitProfile $profile) {
// Make a list of all insert plugins.
$insert_plugins = array();
foreach (linkit_insert_plugin_load_all() as $name => $plugin) {
$insert_plugins[$name] = $plugin['name'];
}
$form['data']['insert_plugin'] = array(
'#type' => 'fieldset',
'#title' => t('Insert methods'),
'#description' => t(''),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
// Settings for insert plugins.
$form['data']['insert_plugin']['plugin'] = array(
'#type' => 'select',
'#title' => t('Insert plugin'),
'#options' => $insert_plugins,
'#empty_option' => t('- Select an insert plugin -'),
'#default_value' => isset($profile->data['insert_plugin']['plugin'])
? $profile->data['insert_plugin'] : '',
'#states' => array(
'visible' => array(
'input[name="profile_type"]' => array('value' => LINKIT_PROFILE_TYPE_FIELD),
),
'required' => array(
'input[name="profile_type"]' => array('value' => LINKIT_PROFILE_TYPE_FIELD),
),
),
);
$form['data']['insert_plugin']['url_method'] = array(
'#title' => t("Insert paths as:"),
'#type' => 'radios',
'#title_display' => 'before',
'#options' => array(
LINKIT_URL_METHOD_RAW => t('Raw paths'),
LINKIT_URL_METHOD_RAW_SLASH => t('Raw paths, with a slash (/) in the beginning.'),
),
LINKIT_URL_METHOD_RAW => array(
'#description' => t('This will insert Drupal internal paths like
%example_link which is probably what you want if you are going to use
this profile together with <strong>fields</strong>.
<br/>If used in textareas, these paths typically need to be formatted
using a input filter, but provides more flexibility in a multilingual
site or when moving a site.', array('%example_link' => 'node/123')),
),
LINKIT_URL_METHOD_RAW_SLASH => array(
'#description' => t('This is the default behavior, it will insert paths
like %example_link.<br/>These will work <strong>without the need for a input filter</strong>,
but might fail after moving a site, or on multilingual sites.',
array('%example_link' => '/node/123')),
),
'#default_value' => isset($profile->data['insert_plugin']['url_method']) ?
$profile->data['insert_plugin']['url_method'] : LINKIT_URL_METHOD_RAW_SLASH,
'#description' => t('These will have no effect on already created links.'),
);
if (module_exists('path')) {
$form['data']['insert_plugin']['url_method']['#options'][LINKIT_URL_METHOD_ALIAS] = t('Alias paths');
$form['data']['insert_plugin']['url_method'][LINKIT_URL_METHOD_ALIAS] = array(
'#description' => t('This will insert the alias for the result item.
<br/>The paths will be runned thru the <em>url()</em> function.', array('%example_link' => 'node/123')),
);
}
}
/**
* Append attribute plugin form element to the profile form.
*
* @param LinkitProfile $profile
* A profile object contains all settings for the profile.
*
* @see linkit_profiles_form()
*/
function _linkit_build_attribute_plugin_form_fields(&$form, LinkitProfile $profile) {
// Load all attribute plugins.
$attributes = linkit_attribute_plugin_load_all();
$form['data']['attribute_plugins_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Attributes'),
'#description' => t('Attributes is HTML attributes that will be attached to
the insert plugin.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => FALSE,
);
$form['data']['attribute_plugins_fieldset']['attribute_plugins'] = array(
'#markup' => '',
'#tree' => TRUE,
'#parents' => array('data', 'attribute_plugins'),
'#theme' => 'linkit_plugin_form_table',
);
// Used to store plugin form elements temporary so we can use this to sort by
// weight later.
$tmp = array();
foreach ($attributes AS $name => $attribute) {
$tmp[$name]['name'] = array('#markup' => $attribute['name']);
$tmp[$name]['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable @title', array('@title' => $attribute['name'])),
'#title_display' => 'invisible',
'#default_value' => isset($profile->data['attribute_plugins'][$name]['enabled'])
? $profile->data['attribute_plugins'][$name]['enabled'] : FALSE,
);
$tmp[$name]['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight for @title', array('@title' => $attribute['name'])),
'#title_display' => 'invisible',
'#default_value' => isset($profile->data['attribute_plugins'][$name]['weight'])
? $profile->data['attribute_plugins'][$name]['weight'] : '',
);
}
// Sort by weight.
uasort($tmp, '_linkit_sort_plugins_by_weight_default_value');
foreach ($tmp AS $name => $element) {
$form['data']['attribute_plugins_fieldset']['attribute_plugins'][$name] = $element;
}
$form['data']['attribute_plugins_fieldset']['attribute_plugins_info'] = array(
'#markup' => 'Keep in mind that not all attributes can be used by all insert plugins.',
);
}
/**
* Append IMCE plugin form element to the profile form.
*
* @param LinkitProfile $profile
* A profile object contains all settings for the profile.
*
* @see linkit_profiles_form()
*/
function _linkit_build_imce_form_fields(&$form, LinkitProfile $profile) {
$form['data']['imce'] = array(
'#type' => 'fieldset',
'#title' => t('IMCE File Picker'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => FALSE,
'#weight' => 80,
);
$form['data']['imce']['use_imce'] = array(
'#title' => t('Enable !imce File Picker', array('!imce' => l(t('IMCE'),
'admin/config/media/imce'))),
'#type' => 'checkbox',
'#description' => t('Note that only public files are supported.'),
'#default_value' => isset($profile->data['imce'])
? $profile->data['imce'] : FALSE,
'#parents' => array('data', 'imce'),
);
}
/**
* Append autocomplete (BAC) form element to the profile form.
*
* @param LinkitProfile $profile
* A profile object contains all settings for the profile.
*
* @see linkit_profiles_form()
*/
function _linkit_build_autocomplete_form_fields(&$form, LinkitProfile $profile) {
$form['data']['autocomplete'] = array(
'#type' => 'fieldset',
'#title' => t('Autocomplete options'),
'#description' => t('Linkit uses !bac which may be configured with focus on
performance.', array('!bac' => l(t('Better Autocomplete'),
'https://github.com/betamos/Better-Autocomplete'))),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
'#weight' => 100,
);
$form['data']['autocomplete']['charLimit'] = array(
'#title' => t('Character limit'),
'#type' => 'textfield',
'#default_value' => isset($profile->data['autocomplete']['charLimit']) ? $profile->data['autocomplete']['charLimit'] : LINKIT_CHAR_LIMIT,
'#size' => 5,
'#description' => t('Minimum number of characters to perform server polling.
A higher value reduces server load. <em>Default: @default</em>', array('@default' => LINKIT_CHAR_LIMIT)),
'#element_validate' => array('linkit_isnumeric_validate'),
);
$form['data']['autocomplete']['wait'] = array(
'#title' => t('Key press delay'),
'#type' => 'textfield',
'#default_value' => isset($profile->data['autocomplete']['wait']) ? $profile->data['autocomplete']['wait'] : LINKIT_WAIT,
'#size' => 5,
'#description' => t('Time from last key press to poll the server. A higher
value reduces server load. <em>Default: @default</em>', array('@default' => LINKIT_WAIT)),
'#field_suffix' => t('ms'),
'#element_validate' => array('linkit_isnumeric_validate'),
);
$form['data']['autocomplete']['remoteTimeout'] = array(
'#title' => t('Remote timeout'),
'#type' => 'textfield',
'#default_value' => isset($profile->data['autocomplete']['remoteTimeout']) ? $profile->data['autocomplete']['remoteTimeout'] : LINKIT_REMOTE_TIMEOUT,
'#size' => 5,
'#description' => t('Client side timeout for a request to the server.
<em>Default: @default</em>', array('@default' => LINKIT_REMOTE_TIMEOUT)),
'#field_suffix' => t('ms'),
'#element_validate' => array('linkit_isnumeric_validate'),
);
}
/**
* Function used by uasort to sort plugin arrays by the weight default value.
*/
function _linkit_sort_plugins_by_weight_default_value($a, $b) {
return $a["weight"]['#default_value'] >= $b["weight"]['#default_value'];
}
/**
* Extract tokens that can be used by the $type.
*
* @param $type
* A string with the entity type.
*/
function linkit_extract_tokens($type) {
// token_info() has it own static cache, so we can call it as we like.
$tokens = token_info();
// If no tokens for the type exists, return an empty array.
if (!isset($tokens['tokens'][$type])) {
return array();
}
$available_tokens = array();
foreach ($tokens['tokens'][$type] as $token_key => $token) {
$available_tokens[] = '[' . $type . ':' . $token_key . ']';
}
return $available_tokens;
}
/**
* Element validate callback for fields that should be numeric.
*
* This function is assigned as an #element_validate callback in
* linkit_profiles_form().
*/
function linkit_isnumeric_validate($element, &$form_state, $form) {
if (!empty($element['#value']) && !is_numeric($element['#value'])) {
form_error($element, $element['#title'] . ' should only contains numbers.');
}
}
@@ -0,0 +1,35 @@
<?php
/**
* @file
* Define Linkit accesskey attribute plugin.
*/
$plugin = array(
'name' => t('Access key'),
'callback' => 'linkit_attribute_plugin_accesskey',
);
/**
* Create a FAPI element.
*
* @param array $plugin
* This is the plugin definition.
*
* @param array $settings
* An array of settings for this attribute. This is from the profile settings.
*
* @return
* An FAPI element.
*
* @see LinkitProfile::setAttributes()
*/
function linkit_attribute_plugin_accesskey($plugin, $settings = array()) {
return array(
'#type' => 'textfield',
'#title' => $plugin['name'],
'#maxlength' => 255,
'#size' => 40,
'#default_value' => '',
'#weight' => isset($settings['weight']) ? $settings['weight'] : 0,
);
}
@@ -0,0 +1,35 @@
<?php
/**
* @file
* Define Linkit class attribute plugin.
*/
$plugin = array(
'name' => t('Classes'),
'callback' => 'linkit_attribute_plugin_class',
);
/**
* Create a FAPI element.
*
* @param array $plugin
* This is the plugin definition.
*
* @param array $settings
* An array of settings for this attribute. This is from the profile settings.
*
* @return
* An FAPI element.
*
* @see LinkitProfile::setAttributes()
*/
function linkit_attribute_plugin_class($plugin, $settings = array()) {
return array(
'#type' => 'textfield',
'#title' => $plugin['name'],
'#maxlength' => 255,
'#size' => 40,
'#default_value' => '',
'#weight' => isset($settings['weight']) ? $settings['weight'] : 0,
);
}
@@ -0,0 +1,35 @@
<?php
/**
* @file
* Define Linkit id attribute plugin.
*/
$plugin = array(
'name' => t('Id'),
'callback' => 'linkit_attribute_plugin_id',
);
/**
* Create a FAPI element.
*
* @param array $plugin
* This is the plugin definition.
*
* @param array $settings
* An array of settings for this attribute. This is from the profile settings.
*
* @return
* An FAPI element.
*
* @see LinkitProfile::setAttributes()
*/
function linkit_attribute_plugin_id($plugin, $settings = array()) {
return array(
'#type' => 'textfield',
'#title' => $plugin['name'],
'#maxlength' => 255,
'#size' => 40,
'#default_value' => '',
'#weight' => isset($settings['weight']) ? $settings['weight'] : 0,
);
}
@@ -0,0 +1,35 @@
<?php
/**
* @file
* Define Linkit rel attribute plugin.
*/
$plugin = array(
'name' => t('Relationship'),
'callback' => 'linkit_attribute_plugin_rel',
);
/**
* Create a FAPI element.
*
* @param array $plugin
* This is the plugin definition.
*
* @param array $settings
* An array of settings for this attribute. This is from the profile settings.
*
* @return
* An FAPI element.
*
* @see LinkitProfile::setAttributes()
*/
function linkit_attribute_plugin_rel($plugin, $settings = array()) {
return array(
'#type' => 'textfield',
'#title' => $plugin['name'],
'#maxlength' => 255,
'#size' => 40,
'#default_value' => '',
'#weight' => isset($settings['weight']) ? $settings['weight'] : 0,
);
}
@@ -0,0 +1,39 @@
<?php
/**
* @file
* Define Linkit target attribute plugin.
*/
$plugin = array(
'name' => t('Target'),
'callback' => 'linkit_attribute_plugin_target',
);
/**
* Create a FAPI element.
*
* @param array $plugin
* This is the plugin definition.
*
* @param array $settings
* An array of settings for this attribute. This is from the profile settings.
*
* @return
* An FAPI element.
*
* @see LinkitProfile::setAttributes()
*/
function linkit_attribute_plugin_target($plugin, $settings = array()) {
return array(
'#type' => 'select',
'#title' => $plugin['name'],
'#options' => array(
'' => '',
'_blank' => t('New window (_blank)'),
'_top' => t('Top window (_top)'),
'_self' => t('Same window (_self)'),
'_parent' => t('Parent window (_parent)')
),
'#weight' => isset($settings['weight']) ? $settings['weight'] : 0,
);
}
@@ -0,0 +1,35 @@
<?php
/**
* @file
* Define Linkit title attribute plugin.
*/
$plugin = array(
'name' => t('Title'),
'callback' => 'linkit_attribute_plugin_title',
);
/**
* Create a FAPI element.
*
* @param array $plugin
* This is the plugin definition.
*
* @param array $settings
* An array of settings for this attribute. This is from the profile settings.
*
* @return
* An FAPI element.
*
* @see LinkitProfile::setAttributes()
*/
function linkit_attribute_plugin_title($plugin, $settings = array()) {
return array(
'#type' => 'textfield',
'#title' => $plugin['name'],
'#maxlength' => 255,
'#size' => 40,
'#default_value' => '',
'#weight' => isset($settings['weight']) ? $settings['weight'] : 0,
);
}
@@ -0,0 +1,10 @@
<?php
/**
* @file
* Defines the HTML link insert plugin.
*/
$plugin = array(
'name' => t('HTML Link'),
'javascript' => 'html_link.js',
);
@@ -0,0 +1,35 @@
/**
* @file
* HTML Link insert plugin for Linkit.
*/
(function ($) {
Drupal.linkit.registerInsertPlugin('html_link', {
insert : function(data) {
var text,
selection = Drupal.settings.linkit.currentInstance.selection;
// Delete all attributes that are empty.
for (name in data.attributes) {
(data.attributes[name]) ? null : delete data.attributes[name];
}
if (typeof selection != 'undefined' &&
selection.text.length >= 1) {
text = selection.text;
}
else {
text = Drupal.settings.linkit.currentInstance.linkContent;
}
// Use document.createElement as it is mush fasten then $('<a/>).
return $(document.createElement('a'))
.attr(data.attributes)
.attr('href', data.path)
.html(text)
// Convert the element to a string.
.get(0).outerHTML;
}
});
})(jQuery);
@@ -0,0 +1,9 @@
<?php
/**
* @file
* Defines the markdown insert plugin.
*/
$plugin = array(
'name' => t('Markdown'),
'javascript' => drupal_get_path('module', 'linkit') . '/plugins/linkit_insert/markdown/markdown.js',
);
@@ -0,0 +1,31 @@
/**
* @file
* Markdown insert plugin for Linkit.
*
* Notes: Markdown dont support any attributes exept "title".
* [An example](http://example.com/ "Title")
*/
(function ($) {
Drupal.linkit.registerInsertPlugin('markdown', {
insert : function(data) {
var pattern = '[!text](!url!title)',
args = {
'!url' : data.path,
'!title' : data.attributes.title ? ' "' + data.attributes.title + '"' : ''
},
selection = Drupal.settings.linkit.currentInstance.selection;
if (typeof selection != 'undefined' &&
selection.text.length >= 1) {
args['!text'] = selection.text;
}
else {
args['!text'] = Drupal.settings.linkit.currentInstance.linkContent;
}
return Drupal.formatString(pattern, args);
}
});
})(jQuery);
@@ -0,0 +1,10 @@
<?php
/**
* @file
* Defines the raw url insert plugin.
*/
$plugin = array(
'name' => t('Raw URL'),
'javascript' => 'raw_url.js',
);
@@ -0,0 +1,11 @@
/**
* @file
* Raw HTML insert plugin for Linkit.
*/
(function ($) {
Drupal.linkit.registerInsertPlugin('raw_url', {
insert : function(data, settings) {
return data.path;
}
});
})(jQuery);
@@ -0,0 +1,334 @@
<?php
/**
* @file
* Define Linkit entity search plugin class.
*/
/**
* Reprecents a Linkit entity search plugin.
*/
class LinkitSearchPluginEntity extends LinkitSearchPlugin {
/**
* Entity field query instance.
*
* @var EntityFieldQuery Resource
*/
var $query;
/**
* The entity info array of an entity type.
*
* @var array
*/
var $entity_info = array();
/**
* The name of the property that contains the entity label.
*
* @var string
*/
var $entity_field_label;
/**
* The name of the property of the bundle object that contains the name of
* the bundle object.
*
* @var string
*/
var $entity_key_bundle;
/**
* Plugin specific settings.
*
* @var array
*/
var $conf = array();
/**
* Overrides LinkitSearchPlugin::__construct().
*
* Initialize this plugin with the plugin, profile, and entity specific
* variables.
*
* @param array $plugin
* The plugin array.
*
* @param LinkitProfile object $profile
* The Linkit profile to use.
*/
function __construct($plugin, LinkitProfile $profile) {
parent::__construct($plugin, $profile);
// Load the corresponding entity info.
$this->entity_info = entity_get_info($this->plugin['entity_type']);
// Set bundle key name.
if (isset($this->entity_info['entity keys']['bundle']) &&
!isset($this->entity_key_bundle)) {
$this->entity_key_bundle = $this->entity_info['entity keys']['bundle'];
}
// Set the label field name.
if (!isset($this->entity_field_label)) {
// Check that the entity has a label in entity keys.
// If not, Linkit don't know what to search for.
if (!isset($this->entity_info['entity keys']['label'])) {
// This is only used when building the plugin list.
$this->unusable = TRUE;
}
else {
$this->entity_field_label = $this->entity_info['entity keys']['label'];
}
}
// Make a shortcut for the profile data settings for this plugin.
$this->conf = isset($this->profile->data[$this->plugin['name']]) ?
$this->profile->data[$this->plugin['name']] : array();
}
/**
* Create a label of an entity.
*
* @param $entity
* The entity to get the label from.
*
* @return
* The entity label, or FALSE if not found.
*/
function createLabel($entity) {
return check_plain(entity_label($this->plugin['entity_type'], $entity));
}
/**
* Create a search row description.
*
* If there is a "result_description", run it thro token_replace.
*
* @param object $data
* An entity object that will be used in the token_place function.
*
* @return
* A string containing the row description.
*
* @see token_replace()
*/
function createDescription($data) {
$description = token_replace(check_plain($this->conf['result_description']), array(
$this->plugin['entity_type'] => $data,
), array('clear' => TRUE));
return $description;
}
/**
* 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;
}
/**
* Create a group text.
*
* @param $entity
* The entity object.
*
* @return
* When "group_by_bundle" is active, we need to add the bundle name to the
* group, else just return the entity label.
*/
function createGroup($entity) {
// Get the entity label.
$group = $this->entity_info['label'];
// If the entities by this entity should be grouped by bundle, get the
// name and append it to the group.
if (isset($this->conf['group_by_bundle']) && $this->conf['group_by_bundle']) {
$bundles = $this->entity_info['bundles'];
$bundle_name = $bundles[$entity->{$this->entity_key_bundle}]['label'];
$group .= ' - ' . check_plain($bundle_name);
}
return $group;
}
/**
* Create a row class to appaned to the search result row.
*
* @param $entity
* The entity object.
*
* @return
* A string to with classes.
*/
function createRowClass($entity) {
return '';
}
/**
* Start a new EntityFieldQuery instance.
*/
function getQueryInstance() {
$this->query = new EntityFieldQuery();
$this->query->entityCondition('entity_type', $this->plugin['entity_type']);
// Add the default sort on the enity label.
$this->query->propertyOrderBy($this->entity_field_label, 'ASC');
}
/**
* Implements LinkitSearchPluginInterface::fetchResults().
*/
public function fetchResults($search_string) {
// If the $search_string is not a string, something is wrong and an empty
// array is returned.
$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($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']) ) {
$bundles = array_filter($this->conf['bundles']);
if ($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->createLabel($entity),
'description' => $this->createDescription($entity),
'path' => $this->createPath($entity),
'group' => $this->createGroup($entity),
'addClass' => $this->createRowClass($entity),
);
}
return $matches;
}
/**
* Overrides LinkitSearchPlugin::buildSettingsForm().
*/
function buildSettingsForm() {
$form[$this->plugin['name']] = array(
'#type' => 'fieldset',
'#title' => t('!type plugin settings', array('!type' => $this->ui_title())),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
'#states' => array(
'invisible' => array(
'input[name="data[search_plugins][' . $this->plugin['name'] . '][enabled]"]' => array('checked' => FALSE),
),
),
);
// Get supported tokens for the entity type.
$tokens = linkit_extract_tokens($this->plugin['entity_type']);
// A short description in within the search result for each row.
$form[$this->plugin['name']]['result_description'] = array(
'#title' => t('Result description'),
'#type' => 'textfield',
'#default_value' => isset($this->conf['result_description']) ? $this->conf['result_description'] : '',
'#size' => 120,
'#maxlength' => 255,
'#description' => t('Available tokens: %tokens.', array('%tokens' => implode(', ', $tokens))),
);
// If the token module is installed, lets make some fancy stuff with the
// token chooser.
if (module_exists('token')) {
// Unset the regular description if token module is enabled.
unset($form[$this->plugin['name']]['result_description']['#description']);
// Display the user documentation of placeholders.
$form[$this->plugin['name']]['token_help'] = array(
'#title' => t('Replacement patterns'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form[$this->plugin['name']]['token_help']['help'] = array(
'#theme' => 'token_tree',
'#token_types' => array($this->plugin['entity_type']),
);
}
// If there is bundles, add some default settings features.
if (count($this->entity_info['bundles']) > 1) {
$bundles = array();
// Extract the bundle data.
foreach ($this->entity_info['bundles'] as $bundle_name => $bundle) {
$bundles[$bundle_name] = $bundle['label'];
}
// Filter the possible bundles to use if the entity has bundles.
$form[$this->plugin['name']]['bundles'] = array(
'#title' => t('Type filter'),
'#type' => 'checkboxes',
'#options' => $bundles,
'#default_value' => isset($this->conf['bundles']) ? $this->conf['bundles'] : array(),
'#description' => t('If left blank, all types will appear in autocomplete results.'),
);
// Group the results with this bundle.
$form[$this->plugin['name']]['group_by_bundle'] = array(
'#title' => t('Group by bundle'),
'#type' => 'checkbox',
'#default_value' => isset($this->conf['group_by_bundle']) ? $this->conf['group_by_bundle'] : 0,
);
}
return $form;
}
}
@@ -0,0 +1,89 @@
<?php
/**
* @file
* Linkit Entity Search Plugin.
*/
/**
* Plugin structure is an associative array containing:
* - ui_title: The title of the plugin used in the admin UI.
* - ui_description: A description used in the admin UI.
* - entity_type: (Only required if the plugin extends LinkitPluginEntity) The
* entity type this plugin will be used for.
* - handler: Describes the class to be used for this plugin.
*/
$plugin = array(
'get child' => 'linkit_entity_ctools_linkit_get_child',
'get children' => 'linkit_entity_ctools_linkit_get_children',
'handler' => array(
'class' => 'LinkitSearchPluginEntity',
'file' => 'entity.class.php',
),
);
/**
* Get a single Linkit search plugin.
*/
function linkit_entity_ctools_linkit_get_child($plugin, $parent, $child) {
$plugins = linkit_entity_ctools_linkit_get_children($plugin, $parent);
return $plugins[$parent . ':' . $child];
}
/**
* Get all child Linkit search plugins.
*/
function linkit_entity_ctools_linkit_get_children($plugin, $parent) {
$entities = entity_get_info();
$plugins = array();
// The alternative plugins is extensions of the provided
// LinkitSearchPluginEntity class provided by Linkit.
$alternative_plugins = array(
'entity:node',
'entity:user',
'entity:taxonomy_term',
'entity:file',
);
foreach ($entities as $entity_type => $entity) {
// The entity must have an URI CALLBACK defined.
if (!isset($entity['uri callback'])) {
continue;
}
$plugin_child = $plugin;
$plugin_child['ui_title'] = $entity['label'];
$plugin_child['ui_description'] = t('Extend Linkit with @entity support.', array('@entity' => $entity_type));
$plugin_child['name'] = $parent . ':' . $entity_type;
$plugin_child['entity_type'] = $entity_type;
// If there is an alternative search class for this entity, change the handler.
if (in_array('entity:' . $entity_type, $alternative_plugins)) {
$handler = array(
'class' => 'LinkitSearchPlugin' . drupal_ucfirst($entity_type),
'file' => $entity_type . '.class.php',
);
$plugin_child['handler'] = $handler;
}
drupal_alter('linkit_search_plugin_entity', $plugin_child, $entity);
$plugins[$parent . ':' . $entity_type] = $plugin_child;
}
drupal_alter('linkit_search_plugin_entities', $plugins);
// Test the plugins.
foreach ($plugins as $plugin_name => $plugin) {
// In some cases the plugins isn't auto loaded. Ctools handle this for us.
// This is typical when installing Linkit.
if (!class_exists($plugin['handler']['class'])) {
continue;
}
$tested_plugin = new $plugin['handler']['class']($plugin, new LinkitProfile());
if (isset($tested_plugin->unusable) && $tested_plugin->unusable) {
unset($plugins[$plugin_name]);
}
}
return $plugins;
}
@@ -0,0 +1,219 @@
<?php
/**
* @file
* Define Linkit file search plugin class.
*/
/**
* Define that file urls should link directly to the file itself.
*/
define('LINKIT_FILE_URL_TYPE_DIRECT', 'direct');
/**
* Define that file urls should force download of the file.
*/
define('LINKIT_FILE_URL_TYPE_DOWNLOAD', 'download');
/**
* Define that file urls should link the file entity view page.
*/
define('LINKIT_FILE_URL_TYPE_ENTITY', 'entity');
/**
* Reprecents a Linkit file search plugin.
*/
class LinkitSearchPluginFile extends LinkitSearchPluginEntity {
/**
* Overrides LinkitSearchPlugin::ui_title().
*/
function ui_title() {
return t('Managed files');
}
/**
* Overrides LinkitSearchPlugin::ui_description().
*/
function ui_description() {
return t('Extend Linkit with file support (Managed files).');
}
/**
* Overrides LinkitSearchPluginEntity::createDescription().
*
* If the file is an image, a small thumbnail can be added to the description.
* Also, image dimensions can be shown.
*/
function createDescription($data) {
$description_array = array();
// Get image info.
$imageinfo = image_get_info($data->uri);
// Add small thumbnail to the description.
if ($this->conf['image_extra_info']['thumbnail']) {
$image = $imageinfo ? theme_image_style(array(
'width' => $imageinfo['width'],
'height' => $imageinfo['height'],
'style_name' => 'linkit_thumb',
'path' => $data->uri,
)) : '';
}
// Add image dimensions to the description.
if ($this->conf['image_extra_info']['dimensions'] && !empty($imageinfo)) {
$description_array[] = $imageinfo['width'] . 'x' . $imageinfo['height'] . 'px';
}
$description_array[] = parent::createDescription($data);
// Add tiel files scheme to the description.
if ($this->conf['show_scheme']) {
$description_array[] = file_uri_scheme($data->uri) . '://';
}
$description = (isset($image) ? $image : '') . implode('<br />' , $description_array);
return $description;
}
/**
* Overrides LinkitSearchPluginEntity::createGroup().
*/
function createGroup($entity) {
// The the standard group name.
$group = parent::createGroup($entity);
// Add the scheme.
if ($this->conf['group_by_scheme']) {
// Get all stream wrappers.
$stream_wrapper = file_get_stream_wrappers();
$group .= ' - ' . $stream_wrapper[file_uri_scheme($entity->uri)]['name'];
}
return $group;
}
/**
* 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);
}
}
/**
* Overrides LinkitSearchPluginEntity::getQueryInstance().
*/
function getQueryInstance() {
// Call the parent getQueryInstance method.
parent::getQueryInstance();
// Only search for permanent files.
$this->query->propertyCondition('status', FILE_STATUS_PERMANENT);
}
/**
* Overrides LinkitSearchPluginEntity::buildSettingsForm().
*/
function buildSettingsForm() {
$form = parent::buildSettingsForm();
$form['entity:file']['show_scheme'] = array(
'#title' => t('Show file scheme'),
'#type' => 'checkbox',
'#default_value' => isset($this->conf['show_scheme']) ? $this->conf['show_scheme'] : '',
);
$form['entity:file']['group_by_scheme'] = array(
'#title' => t('Group files by scheme'),
'#type' => 'checkbox',
'#default_value' => isset($this->conf['group_by_scheme']) ? $this->conf['group_by_scheme'] : '',
);
$form['entity:file']['url_type'] = array(
'#title' => t('URL type'),
'#type' => 'radios',
'#options' => array(
LINKIT_FILE_URL_TYPE_DIRECT => t('Direct file link'),
LINKIT_FILE_URL_TYPE_DOWNLOAD => t('Download file link'),
LINKIT_FILE_URL_TYPE_ENTITY => t('Entity view page'),
),
'#default_value' => 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 (!(module_exists('file_entity') && function_exists('file_entity_download_uri'))) {
unset($form['entity:file']['url_type']['#options'][LINKIT_FILE_URL_TYPE_DOWNLOAD]);
}
$image_extra_info_options = array(
'thumbnail' => t('Show thumbnails <em>(using the image style !linkit_thumb_link)</em>', array('!linkit_thumb_link' => l(t('linkit_thumb'), 'admin/config/media/image-styles/edit/linkit_thumb'))),
'dimensions' => t('Show pixel dimensions'),
);
$form['entity:file']['image_extra_info'] = array(
'#title' => t('Images'),
'#type' => 'checkboxes',
'#options' => $image_extra_info_options,
'#default_value' => isset($this->conf['image_extra_info']) ? $this->conf['image_extra_info'] : array('thumbnail', 'dimensions'),
);
return $form;
}
/**
* Gets the default URL type to use if no URL type has been explicitly set.
*
* @return string The URL type
*/
protected function getDefaultUrlType() {
$info = entity_get_info('file');
$callback = $info['uri callback'];
if ($callback == 'entity_metadata_uri_file') {
// The Drupal core file URI callback would be used if we were to use the
// "Entity view page" URL mode, which generates absolute URLs to files.
// The "Direct link" URL mode is preferable in this case as it generates
// relative links.
return LINKIT_FILE_URL_TYPE_DIRECT;
}
else {
// We use a custom URI callback such as in Media 1.x or File Entity 2.x.
// The "Entity view page" URL mode is preferable in this case.
return LINKIT_FILE_URL_TYPE_ENTITY;
}
}
}
@@ -0,0 +1,51 @@
<?php
/**
* @file
* Define Linkit node search plugin class.
*/
/**
* Reprecents a Linkit node search plugin.
*/
class LinkitSearchPluginNode extends LinkitSearchPluginEntity {
/**
* Overrides LinkitSearchPluginEntity::createRowClass().
*
* Adds an extra class if the node is unpublished.
*/
function createRowClass($entity) {
if ($this->conf['include_unpublished'] && $entity->status == NODE_NOT_PUBLISHED) {
return 'unpublished-node';
}
}
/**
* Overrides LinkitSearchPluginEntity::getQueryInstance().
*/
function getQueryInstance() {
// Call the parent getQueryInstance method.
parent::getQueryInstance();
// If we don't want to include unpublished nodes, add a condition on status.
if ($this->conf['include_unpublished'] == 0) {
$this->query->propertyCondition('status', NODE_PUBLISHED);
}
}
/**
* Overrides LinkitSearchPlugin::buildSettingsForm().
*/
function buildSettingsForm() {
// Get the parent settings form.
$form = parent::buildSettingsForm();
$form[$this->plugin['name']]['include_unpublished'] = array(
'#title' => t('Include unpublished nodes'),
'#type' => 'checkbox',
'#default_value' => isset($this->conf['include_unpublished']) ? $this->conf['include_unpublished'] : 0,
'#description' => t('In order to see unpublished nodes, the user most also have permissions to do so. '),
);
return $form;
}
}
@@ -0,0 +1,96 @@
<?php
/**
* @file
* Define Linkit term search plugin class.
*/
/**
* Reprecents a Linkit term search plugin.
*/
class LinkitSearchPluginTaxonomy_term extends LinkitSearchPluginEntity {
/**
* Overrides LinkitSearchPluginEntity::__construct().
*/
function __construct($plugin, $profile) {
/**
* The term entity doesn't use the same column name as in the entity keys
* bundle definition, so lets add it our self.
*/
$this->entity_key_bundle = 'vid';
parent::__construct($plugin, $profile);
}
/**
* Overrides LinkitSearchPluginEntity::createDescription().
*/
function createDescription($data) {
$description = token_replace(check_plain($this->conf['result_description']), array(
'term' => $data,
), array('clear' => TRUE));
return $description;
}
/**
* Overrides LinkitSearchPluginEntity::createGroup().
*/
function createGroup($entity) {
// Get the entity label.
$group = $this->entity_info['label'];
if (isset($this->conf['group_by_bundle']) && $this->conf['group_by_bundle']) {
$bundles = $this->entity_info['bundles'];
$bundle_name = $bundles[$entity->vocabulary_machine_name]['label'];
$group .= ' - ' . check_plain($bundle_name);
}
return $group;
}
/**
* Overrides LinkitSearchPluginEntity::fetchResults().
*/
function fetchResults($search_string) {
// The term entity doesn't use the entity keys bundle definition, its using
// the vid instead, so lets 'translate' the bundle names to vids.
if (isset($this->entity_key_bundle) && isset($this->conf['bundles']) ) {
$bundles = array_filter($this->conf['bundles']);
// Get all vocabularies.
$vocabularies = taxonomy_vocabulary_get_names();
// Temp storage for values.
$tmp_bundles = array();
foreach ($bundles as $bundle) {
$tmp_bundles[] = $vocabularies[$bundle]->{$this->entity_key_bundle};
}
// Assign the new values as the bundles.
$this->conf['bundles'] = $tmp_bundles;
}
// Call the parent.
return parent::fetchResults($search_string);
}
/**
* Overrides LinkitSearchPlugin::buildSettingsForm().
*/
function buildSettingsForm() {
$form = parent::buildSettingsForm();
// The entity plugin uses the entity name for the #token_types, but terms
// is a special case, its name is "Taxonomy_term" and the tokens are defined
// (in the taxonomy module) with just "term".
// If the token modules is installed.
if (isset($form[$this->plugin['name']]['token_help']['help']['#token_types'])) {
$form[$this->plugin['name']]['token_help']['help']['#token_types'] = array('term');
}
// If the token module is not installed, use the orignal tokens provided by
// Drupal core.
else {
// Get supported tokens for the term entity type.
$tokens = linkit_extract_tokens('term');
$form[$this->plugin['name']]['result_description']['#description'] = t('Available tokens: %tokens.', array('%tokens' => implode(', ', $tokens)));
}
return $form;
}
}
@@ -0,0 +1,24 @@
<?php
/**
* @file
* Define Linkit user search plugin class.
*/
/**
* Reprecents a Linkit user search plugin.
*/
class LinkitSearchPluginUser extends LinkitSearchPluginEntity {
/**
* Overrides LinkitSearchPluginEntity::__construct().
*/
function __construct($plugin, $profile) {
/**
* The user entity doesn't add any label in their entity keys as they define a
* "label callback" instead. Therefore we have to tell which field the user
* entity have as label.
*/
$this->entity_field_label = 'name';
parent::__construct($plugin, $profile);
}
}