updated ctools, needed by panles

This commit is contained in:
Bachir Soussi Chiadmi
2016-10-25 17:47:45 +02:00
parent f6f7fd575f
commit b11abbed59
59 changed files with 779 additions and 297 deletions

View File

@@ -185,7 +185,7 @@ function ctools_entity_from_field_context($context, $conf) {
$loaded_to_entity = array_shift($loaded_to_entity);
// Pass current user account and entity type to access callback.
if (isset($to_entity_info['access callback']) && function_exists($to_entity_info['access callback']) && !call_user_func($to_entity_info['access callback'], 'view', $loaded_to_entity)) {
if (isset($to_entity_info['access callback']) && function_exists($to_entity_info['access callback']) && !call_user_func($to_entity_info['access callback'], 'view', $loaded_to_entity, $account, $to_entity)) {
return ctools_context_create_empty('entity:' . $to_entity, NULL);
}
else {

View File

@@ -0,0 +1,70 @@
<?php
/**
* @file
* Plugin to provide an relationship handler for entities from query string.
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => t('Entity from query string'),
'keyword' => 'query_string_entity',
'description' => t('Entity from query string.'),
'required context' => new ctools_context_required(t('Query string'), 'query_string'),
'context' => 'ctools_entity_from_query_string_context',
'edit form' => 'ctools_entity_from_query_string_settings_form',
);
/**
* Return a new context based on an existing context.
*/
function ctools_entity_from_query_string_context($context, $conf) {
$entity_type = $conf['entity_type'];
// If unset it wants a generic, unfilled context, which is just NULL.
if (empty($context->data) || !isset($context->data) || !is_numeric($context->data)) {
return ctools_context_create_empty('entity:' . $entity_type, NULL);
}
if (!empty($context->data) && is_numeric($context->data)) {
// Load the entity from the query string value.
$entity_id = $context->data;
$entity = entity_load_single($entity_type, $entity_id);
// Send it to ctools.
return ctools_context_create('entity:' . $entity_type, $entity);
}
}
/**
* Settings form for the relationship.
*/
function ctools_entity_from_query_string_settings_form($form, &$form_state) {
//Get all avalible enity types
foreach (entity_get_info() as $key => $value) {
$entity_types[$key] = $value['label'];
}
$form['entity_type'] = array(
'#title' => t('Entity type'),
'#description' => t('Choose entity type to load from query value'),
'#type' => 'select',
'#options' => $entity_types,
);
if (isset($form_state['conf']['entity_type'])) {
$form['entity_type']['#default_value'] = $form_state['conf']['entity_type'];
}
return $form;
}
/**
* Submit handler; settings form for the context.
*/
function ctools_entity_from_query_string_settings_form_submit($form, &$form_state) {
$form_state['conf']['entity_type'] = $form_state['values']['entity_type'];
}

View File

@@ -15,6 +15,8 @@ $plugin = array(
'description' => t('Adds user category edit form from a user context.'),
'required context' => new ctools_context_required(t('User'), 'user'),
'context' => 'ctools_user_category_edit_form_from_user_context',
'edit form' => 'ctools_user_category_edit_form_from_user_settings_form',
'defaults' => array('category' => NULL),
);
/**
@@ -25,7 +27,35 @@ function ctools_user_category_edit_form_from_user_context($context, $conf) {
return ctools_context_create_empty('user_edit_form', NULL);
}
if(!empty($conf['category'])) {
return ctools_context_create('user_edit_form', $context->data, array('category' => $conf['category']));
}
if (isset($context->data->user_category)) {
return ctools_context_create('user_edit_form', $context->data, array('category' => $context->data->user_category));
}
return ctools_context_create('user_edit_form', $context->data);
}
/**
* Settings form for the relationship.
*/
function ctools_user_category_edit_form_from_user_settings_form($form, &$form_state) {
$conf = $form_state['conf'];
$categories = _user_categories();
$options = array();
foreach($categories as $category) {
$options[$category['name']] = $category['title'];
}
$form['category'] = array(
'#type' => 'select',
'#title' => t('Category'),
'#options' => $options,
'#default_value' => isset($conf['category']) ? $conf['category'] : NULL,
'#empty_option' => 'Default',
);
return $form;
}