updated some more modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-01-22 19:41:28 +01:00
parent 8416e3eea1
commit a0fadb0757
271 changed files with 11309 additions and 2135 deletions
@@ -0,0 +1,9 @@
<?php
/**
* Implements hook_cer_fields().
*/
function cer_commerce_cer_fields() {
module_load_include('inc', 'cer', 'cer.cer');
return _cer_collect_fields_of_type('commerce_product_reference', 'CerCommerceProductReferenceField');
}
@@ -0,0 +1,14 @@
name = "CER Commerce"
core = "7.x"
description = "Provides a CER plugin for Commerce's Product Reference fields."
dependencies[] = cer
dependencies[] = commerce_product_reference
files[] = commerce_product_reference.inc
; Information added by Drupal.org packaging script on 2016-02-12
version = "7.x-3.0-alpha7+25-dev"
core = "7.x"
project = "cer"
datestamp = "1455299962"
@@ -0,0 +1,15 @@
<?php
/**
* Implements hook_cer_insert().
*/
function cer_commerce_cer_insert(CerPreset $preset) {
// Prevents a race condition when deleting Commerce products which are referred to
// by Product Reference fields managed by CER.
if ($preset->wrapper->cer_right->chain->value()->end() instanceof CerCommerceProductReferenceField) {
$preset->wrapper->cer_bidirectional->set(FALSE);
$preset->save();
drupal_set_message(t('In order to prevent a race condition, bidirectionality has been disabled for this preset.'), 'warning');
}
}
@@ -0,0 +1,31 @@
<?php
/**
* @file
* Contains a CER plugin for Commerce's Product Reference fields.
*/
class CerCommerceProductReferenceField extends CerField {
/**
* Implements CerField::getTargetType().
*/
public function getTargetType() {
return 'commerce_product';
}
/**
* Overrides CerField::getTargetBundles().
*/
public function getTargetBundles() {
// Product reference fields store their referenceable types by instance
// instead of by field, so the $this->settings variable we inherit
// from CerField is useless here.
$instance = field_info_instance($this->entityType, $this->name, $this->bundle);
$types = $instance['settings']['referenceable_types'];
return ($types ? $types : parent::getTargetBundles());
}
}
@@ -0,0 +1,14 @@
name = "CER Entity Settings"
core = "7.x"
description = "Allows administrators and content authors to override CER settings for individual entities."
dependencies[] = cer
dependencies[] = entityreference
dependencies[] = views
; Information added by Drupal.org packaging script on 2016-02-12
version = "7.x-3.0-alpha7+25-dev"
core = "7.x"
project = "cer"
datestamp = "1455299962"
@@ -0,0 +1,110 @@
<?php
/**
* Implements hook_install().
*/
function cer_entity_settings_install() {
$fields = array();
$fields[] = array(
'active' => 1,
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'deleted' => 0,
'entity_types' => array(),
'field_name' => 'cer_settings',
'foreign keys' => array(
'cer_preset' => array(
'columns' => array(
'target_id' => 'pid',
),
'table' => 'cer_preset',
),
),
'indexes' => array(
'target_id' => array(
0 => 'target_id',
),
),
'locked' => TRUE,
'module' => 'entityreference',
'settings' => array(
// This field uses a simple custom selection handler that selects CER
// presets which apply to the given entity.
'handler' => 'cer',
'handler_settings' => array(
'behaviors' => array(
'views-select-list' => array(
'status' => 0,
),
),
),
'target_type' => 'cer',
),
'translatable' => 0,
'type' => 'entityreference',
);
$fields[] = array(
'active' => 1,
'cardinality' => 1,
'deleted' => 0,
'entity_types' => array(),
'field_name' => 'cer_store_settings',
'foreign keys' => array(),
'indexes' => array(
'value' => array(
0 => 'value',
),
),
'locked' => TRUE,
'module' => 'list',
'settings' => array(
'allowed_values' => array(
0 => 0,
1 => 1,
),
'allowed_values_function' => '',
),
'translatable' => 0,
'type' => 'list_boolean',
);
array_walk($fields, 'field_create_field');
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'cer')->execute();
if (isset($result['cer'])) {
foreach (entity_load('cer', array_keys($result['cer'])) as $preset) {
cer_entity_settings_cer_update($preset);
}
}
}
/**
* Implements hook_uninstall().
*/
function cer_entity_settings_uninstall() {
field_delete_field('cer_settings');
field_delete_field('cer_store_settings');
}
/**
* Implements hook_update_dependencies().
*/
function cer_entity_settings_update_dependencies() {
return array(
'cer_entity_settings' => array(
7001 => array(
'cer' => 7005,
),
),
);
}
/**
* Drops the cer_entity_settings database table.
*/
function cer_entity_settings_update_7001() {
db_drop_table('cer_entity_settings');
cer_entity_settings_install();
}
@@ -0,0 +1,209 @@
<?php
/**
* Implements hook_views_api().
*/
function cer_entity_settings_views_api() {
return array('api' => 3);
}
/**
* Implements hook_query_TAG_alter().
*/
function cer_entity_settings_query_cer_presets_alter(QueryAlterableInterface $query) {
$entity = $query->getMetaData('entity');
$instance = field_info_instance($entity->type(), 'cer_settings', $entity->getBundle());
if ($instance) {
$IDs = array();
foreach ($entity->cer_settings as $preset) {
$IDs[] = $preset->getIdentifier();
}
// If no presets were selected, guarantee an empty result set by selecting
// the non-existent preset ID 0.
if (empty($IDs)) {
$IDs[] = 0;
}
$query->getMetaData('entity_field_query')->entityCondition('entity_id', $IDs, 'IN');
if (! $entity->cer_store_settings->value()) {
$queue = &drupal_static('cer_entity_settings_exit', array());
$queue[ $entity->type() ][ $entity->getIdentifier() ] = $entity;
}
}
}
/**
* Implements hook_exit().
*/
function cer_entity_settings_exit() {
$queue = drupal_static(__FUNCTION__, array());
foreach ($queue as $entity_type => $entities) {
foreach ($entities as $entity) {
// Clear out the stored settings.
$entity->cer_settings->set(NULL);
$entity = $entity->value();
$entity->cer_processed = TRUE;
entity_save($entity_type, $entity);
}
}
}
/**
* Implements hook_cron().
*/
function cer_entity_settings_cron($field = NULL) {
// Delete defunct instances of the given field. An instance is considered
// defunct if there are no presets which refer the entity type and bundle
// on which it's instantiated.
if (isset($field)) {
$view = views_get_view('cer_endpoint_in_use');
$field = field_info_field($field);
// Loop through every instance of the field, executing the view for each one.
foreach ($field['bundles'] as $entity_type => $bundles) {
foreach ($bundles as $bundle) {
$view->set_exposed_input(array(
'left' => "{$entity_type}:{$bundle}:",
'right' => "{$entity_type}:{$bundle}:",
));
$view->execute();
if (empty($view->result)) {
$instance = field_info_instance($entity_type, $field['field_name'], $bundle);
if ($instance) {
// Do NOT delete the field if this is the last instance of it. We
// clean up our own fields during uninstall.
field_delete_instance($instance, FALSE);
}
}
}
}
}
else {
call_user_func(__FUNCTION__, 'cer_settings');
call_user_func(__FUNCTION__, 'cer_store_settings');
}
}
/**
* Implements hook_ctools_plugin_directory().
*/
function cer_entity_settings_ctools_plugin_directory($owner, $plugin_type) {
return "plugins/{$owner}/{$plugin_type}";
}
/**
* Implements hook_cer_insert().
*/
function cer_entity_settings_cer_insert(CerPreset $preset) {
cer_entity_settings_cer_update($preset);
}
/**
* Implements hook_cer_update().
*/
function cer_entity_settings_cer_update(CerPreset $preset) {
_cer_entity_settings_create_instance($preset->wrapper->cer_left->chain->value());
_cer_entity_settings_create_instance($preset->wrapper->cer_right->chain->value());
}
/**
* Instantiates the cer_settings and cer_store_settings fields at the head of
* the given chain, if they aren't already there.
*/
function _cer_entity_settings_create_instance(FieldChain $chain) {
$field = $chain->current();
$instance = field_info_instance($field->entityType, 'cer_settings', $field->bundle);
if (empty($instance)) {
$instance = array(
'bundle' => $field->bundle,
'default_value' => NULL,
'deleted' => 0,
'description' => '',
'display' => array(
'default' => array(
'label' => 'above',
'module' => 'entityreference',
'settings' => array(
'link' => FALSE,
),
'type' => 'entityreference_label',
'weight' => 1,
),
),
'entity_type' => $field->entityType,
'field_name' => 'cer_settings',
'label' => t('Synchronize this @entity_type with...', array(
'@entity_type' => $field->entityTypeLabel,
)),
'required' => 0,
'settings' => array(
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(
'match_operator' => 'CONTAINS',
'path' => '',
'size' => 60,
),
'type' => 'options_buttons',
'weight' => 1,
),
);
field_create_instance($instance);
}
$instance = field_info_instance($field->entityType, 'cer_store_settings', $field->bundle);
if (empty($instance)) {
$instance = array(
'bundle' => $field->bundle,
'default_value' => array(
0 => array(
'value' => 1,
),
),
'deleted' => 0,
'description' => '',
'display' => array(
'default' => array(
'label' => 'above',
'module' => 'list',
'settings' => array(),
'type' => 'list_default',
'weight' => 2,
),
'teaser' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
),
'entity_type' => $field->entityType,
'field_name' => 'cer_store_settings',
'label' => t('Remember these settings'),
'required' => 0,
'settings' => array(
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(
'display_label' => 1,
),
'type' => 'options_onoff',
'weight' => 2,
),
);
field_create_instance($instance);
}
}
@@ -0,0 +1,67 @@
<?php
/**
* Implements hook_views_default_views().
*/
function cer_entity_settings_views_default_views() {
$views = array();
$view = new view();
$view->name = 'cer_endpoint_in_use';
$view->description = '';
$view->tag = 'CER Entity Settings';
$view->base_table = 'cer_preset';
$view->human_name = 'CER Endpoints in Use';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'entity';
$handler->display->display_options['row_options']['view_mode'] = 'default';
$handler->display->display_options['filter_groups']['groups'] = array(
1 => 'OR',
);
/* Filter criterion: CER Preset: Left Field (cer_left) */
$handler->display->display_options['filters']['cer_left_path']['id'] = 'cer_left_path';
$handler->display->display_options['filters']['cer_left_path']['table'] = 'field_data_cer_left';
$handler->display->display_options['filters']['cer_left_path']['field'] = 'cer_left_path';
$handler->display->display_options['filters']['cer_left_path']['operator'] = 'starts';
$handler->display->display_options['filters']['cer_left_path']['group'] = 1;
$handler->display->display_options['filters']['cer_left_path']['exposed'] = TRUE;
$handler->display->display_options['filters']['cer_left_path']['expose']['operator_id'] = 'cer_left_path_op';
$handler->display->display_options['filters']['cer_left_path']['expose']['label'] = 'Left Field';
$handler->display->display_options['filters']['cer_left_path']['expose']['operator'] = 'cer_left_path_op';
$handler->display->display_options['filters']['cer_left_path']['expose']['identifier'] = 'left';
$handler->display->display_options['filters']['cer_left_path']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
);
/* Filter criterion: CER Preset: Right Field (cer_right) */
$handler->display->display_options['filters']['cer_right_path']['id'] = 'cer_right_path';
$handler->display->display_options['filters']['cer_right_path']['table'] = 'field_data_cer_right';
$handler->display->display_options['filters']['cer_right_path']['field'] = 'cer_right_path';
$handler->display->display_options['filters']['cer_right_path']['operator'] = 'starts';
$handler->display->display_options['filters']['cer_right_path']['group'] = 1;
$handler->display->display_options['filters']['cer_right_path']['exposed'] = TRUE;
$handler->display->display_options['filters']['cer_right_path']['expose']['operator_id'] = 'cer_right_path_op';
$handler->display->display_options['filters']['cer_right_path']['expose']['label'] = 'Right Field';
$handler->display->display_options['filters']['cer_right_path']['expose']['operator'] = 'cer_right_path_op';
$handler->display->display_options['filters']['cer_right_path']['expose']['identifier'] = 'right';
$handler->display->display_options['filters']['cer_right_path']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
);
$views[$view->name] = $view;
return $views;
}
@@ -0,0 +1,61 @@
<?php
class CerPresetSelectionHandler implements EntityReference_SelectionHandler {
private $entity;
public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
return new CerPresetSelectionHandler($entity_type, $entity);
}
public function __construct($entity_type, $entity) {
if ($entity_type && $entity) {
$this->entity = new EntityDrupalWrapper($entity_type, $entity);
}
}
public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
$options = array();
if ($this->entity) {
$finder = new CerPresetFinder($this->entity);
$finder->execute();
foreach ($finder->result['cer'] as $preset) {
$options['cer'][$preset->pid] = $preset->label_variables['@right'];
}
foreach ($finder->result['cer__invert'] as $preset) {
$options['cer'][$preset->pid] = $preset->label_variables['@left'];
}
}
return $options;
}
public function countReferencableEntities($match = NULL, $match_operator = 'CONTAINS') {
return sizeof($this->getReferencableEntities());
}
public function validateReferencableEntities(array $IDs) {
// Don't bother validating preset IDs.
return $IDs;
}
public function validateAutocompleteInput($input, &$element, &$form_state, $form) {
return NULL;
}
public function entityFieldQueryAlter(SelectQueryInterface $query) {
// NOP
}
public function getLabel($entity) {
return entity_label('cer', $entity);
}
public static function settingsForm($field, $instance) {
return array();
}
}
@@ -0,0 +1,6 @@
<?php
$plugin = array(
'title' => t('CER Presets'),
'class' => 'CerPresetSelectionHandler',
);
@@ -0,0 +1,12 @@
name = "CER Inline Entity Form"
core = "7.x"
description = "Provides an option to hide CER fields on Inline Entity Forms."
dependencies[] = cer
dependencies[] = inline_entity_form
; Information added by Drupal.org packaging script on 2016-02-12
version = "7.x-3.0-alpha7+25-dev"
core = "7.x"
project = "cer"
datestamp = "1455299962"
@@ -0,0 +1,94 @@
<?php
/**
* @file
* Provides an option to hide CER fields on inline entity forms. Spun off
* from Issue #2240371.
*/
/**
* Implements hook_form_FORM_ID_alter().
*/
function cer_ief_form_field_ui_field_edit_form_alter(array &$form, array &$form_state) {
// Add options to hide corresponding entity reference fields on inline entity forms.
$instance = $form['#instance'];
if ($instance['widget']['type'] == 'inline_entity_form') {
// Build a filter to fetch matching CER presets for this field instance.
$entity_type = $instance['entity_type'];
$bundle = $instance['bundle'];
$field_name = $instance['field_name'];
$filter = "{$entity_type}:{$bundle}:{$field_name}";
if ($presets = _cer_filter_presets($filter)) {
// There are available CER configurations for this IEF instance.
// Add option to hide field(s) on referenced entities.
$ief_settings = &$form['instance']['widget']['settings']['type_settings'];
$ief_settings['hide_cer_fields'] = array(
'#type' => 'checkbox',
'#title' => t('Hide corresponding entity reference field(s) on form.'),
'#default_value' => !empty($instance['widget']['settings']['type_settings']['hide_cer_fields']),
);
// @todo Add checkbox for each corresponding field?
// foreach ($presets as $preset) etc.
}
}
}
/**
* Implements hook_field_widget_form_alter().
*
* @todo This could be cached into an array and only rebuilt when a contextual
* field instance is updated or CER pattern added/removed.
*/
function cer_ief_field_widget_form_alter(array &$element, array &$form_state, array $context) {
// Only concerns fields within Inline Entity Forms.
if (isset($context['form']['#ief_id'])) {
// Get the form ID.
$ief_id = $context['form']['#ief_id'];
// Get instance information for the IEF field.
$ief_field_instance = $form_state['inline_entity_form'][$ief_id]['instance'];
// Check if "hide" is enabled on the IEF that is holding this field.
$hide_cer_fields = !empty($ief_field_instance['widget']['settings']['type_settings']['hide_cer_fields']);
if ($hide_cer_fields) {
// Get available CER chains. We use an ordinary static as this will be called for
// each field that belongs to an IEF with 'hide' enabled -- could be a lot.
static $plugins;
if (! isset($plugins)) {
// Load available CER field keys into a map. The actual plugin info isn't needed.
// We use drupal_map_assoc() so we can do isset() checks for plugins instead
// of calling in_array().
$plugins = drupal_map_assoc(array_keys(CerField::getPluginInfo()));
}
// Set up filter chains for the affected entities. The left chain is for the entity
// that has the IEF field on it, and the right chain is for the entity *in* the IEF.
$left_chain = $ief_field_instance['entity_type'] . ':' . $ief_field_instance['bundle'] . ':' . $ief_field_instance['field_name'];
$right_chain = $context['instance']['entity_type'] . ':' . $context['instance']['bundle'] . ':' . $context['instance']['field_name'];
// Ensure that both fields are CER fields. If they're not, bail out.
if (! isset($plugins[$left_chain], $plugins[$right_chain])) {
return;
}
// If a preset from parent to IEF exists, prevent access to the field.
foreach (_cer_filter_presets($left_chain) as $preset) {
// Check if the preset's right hand points to the instance found in the IEF.
if (strpos($preset->right, $right_chain) === 0) {
$match = TRUE;
}
elseif ($preset->bidirectional && strpos($preset->left, $right_chain) === 0) {
$match = TRUE;
}
// Matching chain found. Prevent access to this field and return.
if (isset($match)) {
$element['#access'] = FALSE;
return;
}
}
}
}
}
@@ -0,0 +1,33 @@
<?php
/**
* Implements hook_cer_fields().
*/
function cer_profile2_cer_fields() {
$fields = array();
// Create a fake field for each Profile2 type.
foreach (array_keys(profile2_get_types()) as $profile_type) {
// Profiles can only be attached to user accounts.
$fields["user:user:profile_{$profile_type}"]['class'] = 'CerProfile2Field';
}
return $fields;
}
/**
* Implements hook_cer_fields_alter().
*/
function cer_profile2_cer_fields_alter(array &$fields) {
foreach (array_keys($fields) as $identifier) {
list ($entity_type, $bundle) = explode(':', $identifier);
// If this field is instantiated on a Profile2, make CER treat it like a field
// collection by first setting its parent field, and setting the 'require parent'
// flag so that CER won't allow it to stand alone in a field chain.
if ($entity_type == 'profile2') {
$fields[$identifier]['parents'][] = "user:user:profile_{$bundle}";
$fields[$identifier]['require parent'] = TRUE;
}
}
}
@@ -0,0 +1,13 @@
name = "CER Profile2"
core = "7.x"
description = "Allows CER to relate user references to Profile2 fields."
dependencies[] = cer
dependencies[] = profile2
files[] = profile2.inc
; Information added by Drupal.org packaging script on 2016-02-12
version = "7.x-3.0-alpha7+25-dev"
core = "7.x"
project = "cer"
datestamp = "1455299962"
@@ -0,0 +1,23 @@
<?php
/**
* Implements hook_disable().
*/
function cer_profile2_disable() {
foreach (entity_load('cer', FALSE) as $preset) {
if (_cer_profile2_is_profile2_preset($preset)) {
$preset->wrapper->cer_enabled->set(FALSE);
}
}
}
/**
* Implements hook_uninstall().
*/
function cer_profile2_uninstall() {
foreach (entity_load('cer', FALSE) as $preset) {
if (_cer_profile2_is_profile2_preset($preset)) {
entity_delete('cer', $preset->pid);
}
}
}
@@ -0,0 +1,55 @@
<?php
define('CER_PROFILE2_PATTERN', '/^user:user:profile_/');
/**
* Returns if either side of a preset refers to a profile2.
*
* @param \CerPreset $preset
* The preset to test.
*
* @return bool
*/
function _cer_profile2_is_profile2_preset(CerPreset $preset) {
return preg_match(CER_PROFILE2_PATTERN, $preset->wrapper->cer_left->value()) || preg_match(CER_PROFILE2_PATTERN, $preset->wrapper->cer_right->value());
}
/**
* Implements hook_entity_property_info_alter().
*/
function cer_profile2_entity_property_info_alter(array &$info) {
$struct = &$info['profile2']['properties']['cer']['property info'];
$struct['lineage']['getter callback'] = 'cer_profile2_get_profile2_lineage';
$struct['depth']['getter callback'] = 'cer_profile2_get_profile2_depth';
$struct['owner']['getter callback'] = 'cer_profile2_get_profile2_owner';
}
/**
* Entity API getter callback. Returns the lineage of a Profile2 entity.
*
* @return string
*/
function cer_profile2_get_profile2_lineage(array $data, array $options, $property, $data_type, array $info) {
return 'user:user:profile_' . $data[1]->type . ':profile2:' . $data[1]->type . ':';
}
/**
* Entity API getter callback. Returns the depth of a Profile2. This is always
* 1, since the profile is embedded directly under the user account as far
* as CER is concerned.
*
* @return integer
*/
function cer_profile2_get_profile2_depth(array $data, array $options, $property, $data_type, array $info) {
return 1;
}
/**
* Entity API getter callback. Returns the user account which owns a Profile2.
*
* @return EntityDrupalWrapper.
*/
function cer_profile2_get_profile2_owner(array $data, array $options, $property, $data_type, array $info) {
return new EntityDrupalWrapper('user', $data[1]->user());
}
@@ -0,0 +1,71 @@
<?php
/**
* @file
* Contains a CER field plugin for referencing Profile2 entities. These references
* are not actually fields at all, so this plugin is really more of a bridge to
* trick CER into thinking that Profile2 is a reference field.
*/
class CerProfile2Field extends CerField implements CerEntityContainerInterface {
protected $profileType;
/**
* @override CerField::__construct().
*/
public function __construct(array $plugin) {
$this->plugin = $plugin;
list ($this->entityType, $this->bundle, $this->name) = explode(':', $plugin['identifier']);
$info = entity_get_info($this->entityType);
// These "fields" can only be instantiated on user accounts, which are
// normally not bundleable. However, there could be a module in the wild
// which makes accounts bundleable, so let's not be presumptuous here.
$this->isBundleable = (boolean) $info['entity keys']['bundle'];
$this->entityTypeLabel = $info['label'];
$this->bundleLabel = $info['bundles'][$this->bundle]['label'];
// An account can only have one profile of this type.
$this->cardinality = 1;
$this->fieldTypeLabel = t('Profile');
// Load the Profile2 type information
$this->profileType = profile2_get_types(subStr($this->name, 8));
$this->label = $this->profileType->label;
}
/**
* Implements CerField::getTargetType().
*/
public function getTargetType() {
// In effect, this "field" will "point to" Profile2 entities.
return 'profile2';
}
/**
* @override CerField::getTargetBundles().
*/
public function getTargetBundles() {
// This field can only "reference" one type of profile. There'll be
// a separate instance of this plugin for each Profile2 type.
return (array) $this->profileType->type;
}
/**
* Implements CerEntityContainerInterface::createInnerEntity().
*/
public function createInnerEntity(EntityDrupalWrapper $owner) {
$init = array(
'user' => $owner->value(),
'type' => $this->profileType,
);
// Create a blank profile for this user, and save it. The "reference" is implied
// by the existence of the profile.
$profile = profile2_create($init);
$profile->save();
return $profile;
}
}