diff --git a/PATCH_LIST.txt b/PATCH_LIST.txt
index 01e5753f..17696785 100644
--- a/PATCH_LIST.txt
+++ b/PATCH_LIST.txt
@@ -29,3 +29,7 @@ views_rss_media
node_export :
- https://www.drupal.org/node/1869918
- https://www.drupal.org/node/1911638
+login_tobogan (pd with field permission et donc field collection)
+ - https://www.drupal.org/node/1365764#comment-10286257
+ - logintoboggan-exempting_lt_preauth_role_from_user_permissions_js-1365764-52.patch
+ - interdiff-1365764-23-52-do-not-test.diff
diff --git a/interdiff-1365764-23-52-do-not-test.diff b/interdiff-1365764-23-52-do-not-test.diff
new file mode 100644
index 00000000..ba3ab8f8
--- /dev/null
+++ b/interdiff-1365764-23-52-do-not-test.diff
@@ -0,0 +1,14 @@
+diff --git a/logintoboggan.permissions.js b/logintoboggan.permissions.js
+index d463d29..492b64c 100644
+--- a/logintoboggan.permissions.js
++++ b/logintoboggan.permissions.js
+@@ -14,6 +14,9 @@ Drupal.behaviors.LoginTobogganPermissions = {
+ $('table#permissions', context).once('tobogganPermissions', function () {
+ $('input[type=checkbox]', this).filter('.rid-' + settings.LoginToboggan.preAuthID).removeClass('real-checkbox').each(function () {
+ $(this).next().filter('.dummy-checkbox').remove();
++ $('input.rid-' + settings.LoginToboggan.preAuthID).each(function () {
++ this.style.display = '';
++ });
+ });
+ });
+ },
diff --git a/logintoboggan-exempting_lt_preauth_role_from_user_permissions_js-1365764-52.patch b/logintoboggan-exempting_lt_preauth_role_from_user_permissions_js-1365764-52.patch
new file mode 100644
index 00000000..c8b4ceae
--- /dev/null
+++ b/logintoboggan-exempting_lt_preauth_role_from_user_permissions_js-1365764-52.patch
@@ -0,0 +1,136 @@
+diff --git a/logintoboggan.module b/logintoboggan.module
+index 55b93fe..4e4e0fc 100644
+--- a/logintoboggan.module
++++ b/logintoboggan.module
+@@ -306,26 +306,6 @@ function logintoboggan_form_user_pass_reset_alter(&$form, &$form_state) {
+ }
+
+ /**
+- * Implement hook_form_user_admin_permissions_alter().
+- *
+- * @ingroup logintoboggan_core
+- */
+-function logintoboggan_form_user_admin_permissions_alter(&$form, &$form_state) {
+- // If the pre-auth role isn't the auth user, then add it as a setting.
+- $id = logintoboggan_validating_id();
+- if ($id != DRUPAL_AUTHENTICATED_RID) {
+- $form['#attached']['js'][] = array(
+- 'data' => array(
+- 'LoginToboggan' => array(
+- 'preAuthID' => $id,
+- ),
+- ),
+- 'type' => 'setting',
+- );
+- }
+-}
+-
+-/**
+ * Implement hook_form_alter().
+ *
+ * @ingroup logintoboggan_core
+@@ -410,7 +390,10 @@ function logintoboggan_js_alter(&$javascript) {
+ // prevent the pre-auth role's checkboxes from being automatically disabled
+ // when the auth user's checkboxes are checked.
+ if ($id != DRUPAL_AUTHENTICATED_RID) {
+- $javascript['modules/user/user.permissions.js']['data'] = drupal_get_path('module', 'logintoboggan') . '/logintoboggan.permissions.js';
++ $javascript['settings']['data'][] = array('LoginToboggan' => array('preAuthID' => $id));
++ $file = drupal_get_path('module', 'logintoboggan') . '/logintoboggan.permissions.js';
++ $javascript[$file] = drupal_js_defaults($file);
++ $javascript[$file]['weight'] = 999;
+ }
+ }
+ }
+diff --git a/logintoboggan.permissions.js b/logintoboggan.permissions.js
+index 1d406cc..492b64c 100644
+--- a/logintoboggan.permissions.js
++++ b/logintoboggan.permissions.js
+@@ -1,77 +1,25 @@
+
+ /**
+- * This is a custom implementation of user.permissions.js, which is necessary
+- * because LoginToboggan needs its pre-auth role to not be explicitly tied to
+- * the auth role. The change is minor -- simply exclude the pre-auth role from
+- * all the auto-checking as the anon and auth user roles are.
++ * LoginToboggan needs its pre-auth role to not be explicitly tied to
++ * the auth role.
+ */
+-
+ (function ($) {
+
+ /**
+ * Shows checked and disabled checkboxes for inherited permissions.
+ */
+-Drupal.behaviors.permissions = {
+- attach: function (context) {
+- var self = this;
+- $('table#permissions').once('permissions', function () {
+- // On a site with many roles and permissions, this behavior initially has
+- // to perform thousands of DOM manipulations to inject checkboxes and hide
+- // them. By detaching the table from the DOM, all operations can be
+- // performed without triggering internal layout and re-rendering processes
+- // in the browser.
+- var $table = $(this);
+- if ($table.prev().length) {
+- var $ancestor = $table.prev(), method = 'after';
+- }
+- else {
+- var $ancestor = $table.parent(), method = 'append';
+- }
+- $table.detach();
+-
+- // Create dummy checkboxes. We use dummy checkboxes instead of reusing
+- // the existing checkboxes here because new checkboxes don't alter the
+- // submitted form. If we'd automatically check existing checkboxes, the
+- // permission table would be polluted with redundant entries. This
+- // is deliberate, but desirable when we automatically check them.
+- var $dummy = $('')
+- .attr('title', Drupal.t("This permission is inherited from the authenticated user role."))
+- .hide();
+-
+- $('input[type=checkbox]', this).not('.rid-2, .rid-1, .rid-' + Drupal.settings.LoginToboggan.preAuthID).addClass('real-checkbox').each(function () {
+- $dummy.clone().insertAfter(this);
++Drupal.behaviors.LoginTobogganPermissions = {
++ attach: function (context, settings) {
++ // Revert changes made by modules/user/user.permissions.js
++ $('table#permissions', context).once('tobogganPermissions', function () {
++ $('input[type=checkbox]', this).filter('.rid-' + settings.LoginToboggan.preAuthID).removeClass('real-checkbox').each(function () {
++ $(this).next().filter('.dummy-checkbox').remove();
++ $('input.rid-' + settings.LoginToboggan.preAuthID).each(function () {
++ this.style.display = '';
++ });
+ });
+-
+- // Initialize the authenticated user checkbox.
+- $('input[type=checkbox].rid-2', this)
+- .bind('click.permissions', self.toggle)
+- // .triggerHandler() cannot be used here, as it only affects the first
+- // element.
+- .each(self.toggle);
+-
+- // Re-insert the table into the DOM.
+- $ancestor[method]($table);
+ });
+ },
+-
+- /**
+- * Toggles all dummy checkboxes based on the checkboxes' state.
+- *
+- * If the "authenticated user" checkbox is checked, the checked and disabled
+- * checkboxes are shown, the real checkboxes otherwise.
+- */
+- toggle: function () {
+- var authCheckbox = this, $row = $(this).closest('tr');
+- // jQuery performs too many layout calculations for .hide() and .show(),
+- // leading to a major page rendering lag on sites with many roles and
+- // permissions. Therefore, we toggle visibility directly.
+- $row.find('.real-checkbox').each(function () {
+- this.style.display = (authCheckbox.checked ? 'none' : '');
+- });
+- $row.find('.dummy-checkbox').each(function () {
+- this.style.display = (authCheckbox.checked ? '' : 'none');
+- });
+- }
+ };
+
+ })(jQuery);
diff --git a/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.css b/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.css
index e6185071..61af1494 100644
--- a/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.css
+++ b/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.css
@@ -1,4 +1,3 @@
-
/* Table cells. */
.field-permissions-cell,
.field-permissions-header {
@@ -29,20 +28,19 @@ html.js .field-permissions-tooltip {
color: #444;
background-color: #f0f0f0;
border: 1px solid #aaa;
-
/* CSS3 properties not supported by all browsers. */
-webkit-box-shadow: 2px 2px 2px #ccc;
- -khtml-box-shadow: 2px 2px 2px #ccc;
- -icab-box-shadow: 2px 2px 2px #ccc;
- -moz-box-shadow: 2px 2px 2px #ccc;
- -o-box-shadow: 2px 2px 2px #ccc;
- box-shadow: 2px 2px 2px #ccc;
+ -khtml-box-shadow: 2px 2px 2px #ccc;
+ -icab-box-shadow: 2px 2px 2px #ccc;
+ -moz-box-shadow: 2px 2px 2px #ccc;
+ -o-box-shadow: 2px 2px 2px #ccc;
+ box-shadow: 2px 2px 2px #ccc;
-webkit-border-radius: 5px;
- -khtml-border-radius: 5px;
- -icab-border-radius: 5px;
- -moz-border-radius: 5px;
- -o-border-radius: 5px;
- border-radius: 5px;
+ -khtml-border-radius: 5px;
+ -icab-border-radius: 5px;
+ -moz-border-radius: 5px;
+ -o-border-radius: 5px;
+ border-radius: 5px;
}
.field-permissions-tooltip .item-list,
#field-permissions-tooltip .item-list {
diff --git a/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.inc b/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.inc
index fde37306..2eeefd55 100644
--- a/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.inc
+++ b/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.inc
@@ -8,13 +8,13 @@
/**
* Obtain the list of field permissions.
*
- * @param $field_label
+ * @param string $field_label
* The human readable name of the field to use when constructing permission
* names. Usually this will be derived from one or more of the field instance
* labels.
*/
function field_permissions_list($field_label = '') {
- return array(
+ $permissions = array(
'create' => array(
'label' => t('Create field'),
'title' => t('Create own value for field %field', array('%field' => $field_label)),
@@ -36,46 +36,47 @@ function field_permissions_list($field_label = '') {
'title' => t("View anyone's value for field %field", array('%field' => $field_label)),
),
);
+
+ drupal_alter('field_permissions_list', $permissions, $field_label);
+
+ return $permissions;
}
/**
* Returns field permissions in a format suitable for use in hook_permission().
*
- * @param $field
+ * @param array $field
* The field to return permissions for.
- * @param $label
+ * @param mixed $label
* (optional) The human readable name of the field to use when constructing
* permission names; for example, this might be the label of one of the
* corresponding field instances. If not provided, an appropriate label will
* be automatically derived from all the field's instances.
*
- * @return
+ * @return array
* An array of permission information, suitable for use in hook_permission().
*/
function field_permissions_list_field_permissions($field, $label = NULL) {
- $description = '';
-
- // If there is no preferred label, construct one from all the instance
- // labels.
if (!isset($label)) {
- $labels = array();
- foreach ($field['bundles'] as $entity_type => $bundles) {
- foreach ($bundles as $bundle_name) {
- $instance = field_info_instance($entity_type, $field['field_name'], $bundle_name);
- $labels[] = $instance['label'];
+ $label = $field['field_name'];
+ }
+ $instances = array();
+ $description = '';
+ foreach ($field['bundles'] as $entity_type => $bundles) {
+ foreach ($bundles as $bundle_name) {
+ $instance = field_info_instance($entity_type, $field['field_name'], $bundle_name);
+ $entity = entity_get_info($entity_type);
+ if (!isset($entity['bundles'][$bundle_name])) {
+ continue;
}
+ $instance_desc_tokens = array(
+ $entity['label'],
+ $entity['bundles'][$bundle_name]['label'],
+ $instance['label'],
+ );
+ $instances[] = '"' . implode(':', $instance_desc_tokens) . '"';
}
- // If all the instances have the same label, just use that. Otherwise, use
- // the field name (with the full list of instance labels as the permission
- // description).
- $labels = array_unique($labels);
- if (count($labels) == 1) {
- $label = array_shift($labels);
- }
- else {
- $label = $field['field_name'];
- $description = t('This field appears as: %instances', array('%instances' => implode(', ', $labels)));
- }
+ $description = t('This field appears as: %instances.', array('%instances' => implode(', ', $instances)));
}
$permissions = array();
@@ -91,7 +92,7 @@ function field_permissions_list_field_permissions($field, $label = NULL) {
}
/**
- * Implementation of hook_permission().
+ * Implements hook_permission().
*/
function _field_permissions_permission() {
$perms = array(
@@ -145,9 +146,7 @@ function _field_permissions_field_settings_form_alter(&$form, $form_state, $form
'#type' => 'container',
'#states' => array(
'visible' => array(
- // We must cast this to a string until http://drupal.org/node/879580 is
- // fixed.
- ':input[name="field[field_permissions][type]"]' => array('value' => (string) FIELD_PERMISSIONS_CUSTOM),
+ ':input[name="field[field_permissions][type]"]' => array('value' => FIELD_PERMISSIONS_CUSTOM),
),
),
// Custom styling for the permissions matrix on the field settings page.
@@ -156,6 +155,23 @@ function _field_permissions_field_settings_form_alter(&$form, $form_state, $form
),
);
+ $form['field']['field_permissions']['permission_warning'] = array(
+ '#type' => 'item',
+ '#markup' => '
'
+ . t('Field permissions error')
+ . ' '
+ . t('If you are seeing this message and are not seeing a table of permissions, something is wrong! See !link for more information.', array(
+ '!link' => l(t('the Field Permission documentation'), 'https://www.drupal.org/node/2802067#known-issues', array(
+ 'attributes' => array('target' => '_blank'),
+ )),
+ )) . '
',
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="field[field_permissions][type]"]' => array('value' => FIELD_PERMISSIONS_CUSTOM),
+ ),
+ ),
+ );
+
// Add the field permissions matrix itself. Wait until the #pre_render stage
// to move it to the above container, to avoid having the permissions data
// saved as part of the field record.
@@ -183,15 +199,15 @@ function _field_permissions_field_settings_form_alter(&$form, $form_state, $form
* to actually be saved. For an example submit handler, see
* _field_permissions_field_settings_form_submit().
*
- * @param $field
+ * @param array $field
* The field whose permissions will be displayed in the matrix.
- * @param $instance
+ * @param array $instance
* The field instance for which the permissions will be displayed. Although
* the permissions are per-field rather than per-instance, the instance label
* will be used to display an appropriate human-readable name for each
* permission.
*
- * @return
+ * @return array
* A form array defining the permissions matrix.
*
* @see user_admin_permissions()
@@ -327,37 +343,52 @@ function _field_permissions_field_settings_form_submit($form, &$form_state) {
* Menu callback; Field permissions overview.
*/
function field_permissions_overview() {
- drupal_add_css(drupal_get_path('module', 'field_permissions') .'/field_permissions.admin.css');
+ drupal_add_css(drupal_get_path('module', 'field_permissions') . '/field_permissions.admin.css');
- $headers = array(t('Field name'), t('Field type'), t('Entity type'), t('Used in'));
+ $headers = array(
+ t('Field name'),
+ t('Field type'),
+ t('Entity type'),
+ t('Used in'),
+ );
foreach (field_permissions_list() as $permission_type => $permission_info) {
$headers[] = array('data' => $permission_info['label'], 'class' => 'field-permissions-header');
}
$destination = drupal_get_destination();
- // Load list of field instances, types and bundles in the system.
- $instances = field_info_instances();
+ // Load list of fields, field types and bundles in the system.
$field_types = field_info_field_types();
- $bundles = field_info_bundles();
+ $bundles_info = field_info_bundles();
// Retrieve the permissions for each role.
$role_permissions = user_role_permissions(user_roles());
// Based on field_ui_fields_list() in field_ui.admin.inc.
$rows = array();
- foreach ($instances as $obj_type => $type_bundles) {
- foreach ($type_bundles as $bundle => $bundle_instances) {
- foreach ($bundle_instances as $field_name => $instance) {
+ foreach (field_info_fields() as $field_name => $field) {
+ foreach ($field['bundles'] as $entity_type => $bundles) {
+ foreach ($bundles as $bundle) {
+ // Some fields might belong to bundles that are disabled (which are not
+ // returned by field_info_bundles()).
+ // @see https://www.drupal.org/node/1351506
+ if (!isset($bundles_info[$entity_type][$bundle])) {
+ continue;
+ }
// Each field will have a row in the table.
- $field = field_info_field($field_name);
- $admin_path = _field_ui_bundle_admin_path($obj_type, $bundle);
+ if (module_exists('field_ui')) {
+ $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
+ $field_admin_path = l($bundles_info[$entity_type][$bundle]['label'], $admin_path . '/fields/' . $field_name, array(
+ 'query' => $destination,
+ 'fragment' => 'edit-field-field-permissions-type',
+ ));
+ }
+ else {
+ $field_admin_path = $bundles_info[$entity_type][$bundle]['label'];
+ }
$rows[$field_name]['data'][0] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name;
- $rows[$field_name]['data'][1] = t($field_types[$field['type']]['label']);
- $rows[$field_name]['data'][2] = $obj_type;
- $rows[$field_name]['data'][3][] = l($bundles[$obj_type][$bundle]['label'], $admin_path . '/fields/'. $field_name, array(
- 'query' => $destination,
- 'fragment' => 'edit-field-field-permissions-type',
- ));
+ $rows[$field_name]['data'][1] = $field_types[$field['type']]['label'];
+ $rows[$field_name]['data'][2] = $entity_type;
+ $rows[$field_name]['data'][3][] = $field_admin_path;
$rows[$field_name]['class'] = $field['locked'] ? array('menu-disabled') : array('');
// Append field permissions information to the report.
@@ -381,7 +412,7 @@ function field_permissions_overview() {
$all_users_have_access = isset($role_permissions[DRUPAL_ANONYMOUS_RID][$permission]) && isset($role_permissions[DRUPAL_AUTHENTICATED_RID][$permission]);
$status_class = $all_users_have_access ? 'field-permissions-status-on' : 'field-permissions-status-off';
$title = $all_users_have_access ? t('All users have this permission') : t('Not all users have this permission');
- $data = l('', 'admin/people/permissions', array(
+ $data = l(NULL, 'admin/people/permissions', array(
'attributes' => array(
'class' => array('field-permissions-status', $status_class),
'title' => $title,
@@ -416,7 +447,7 @@ function field_permissions_overview() {
// Allow external modules alter the table headers and rows.
foreach (module_implements('field_permissions_overview_alter') as $module) {
- $function = $module .'_field_permissions_overview_alter';
+ $function = $module . '_field_permissions_overview_alter';
$function($headers, $rows);
}
diff --git a/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.js b/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.js
index 19aae57a..76ca19da 100644
--- a/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.js
+++ b/sites/all/modules/contrib/admin/field_permissions/field_permissions.admin.js
@@ -1,63 +1,74 @@
+/**
+ * @file
+ */
+
(function ($) {
-Drupal.behaviors.fieldPermissionsSettings = {
- attach: function (context) {
- // For user fields, we want the "Create own value for field X" permission
- // row to only be displayed when it's meaningful (i.e., when the "Display
- // on user registration form" checkbox is checked).
- var $user_register_form_checkbox, $required_field_checkbox, $create_permission_row;
- $user_register_form_checkbox = $('.form-item-instance-settings-user-register-form .form-checkbox', context);
- if ($user_register_form_checkbox.length) {
- // The "Required field" checkbox can cause the user registration checkbox
- // to change, so we need it also.
- $required_field_checkbox = $('.form-item-instance-required .form-checkbox', context);
- if ($required_field_checkbox.length) {
- // Get the permissions table row corresponding to the "Create own value
- // for field X" permission. The theme_user_admin_permissions() function
- // does not give us a good way to directly detect which row contains
- // the create permissions, so we have rely on the fact that it will be
- // the first row.
- $create_permission_row = $('table#permissions tbody tr', context).filter(':first');
- new Drupal.fieldPermissions.HideCreatePermission($user_register_form_checkbox, $required_field_checkbox, $create_permission_row);
+ Drupal.behaviors.fieldPermissionsSettings = {
+ attach: function (context) {
+ // For user fields, we want the "Create own value for field X" permission
+ // row to only be displayed when it's meaningful (i.e., when the "Display
+ // on user registration form" checkbox is checked).
+ var $user_register_form_checkbox, $required_field_checkbox, $create_permission_row;
+ $user_register_form_checkbox = $('.form-item-instance-settings-user-register-form .form-checkbox', context);
+ if ($user_register_form_checkbox.length) {
+ // The "Required field" checkbox can cause the user registration checkbox
+ // to change, so we need it also.
+ $required_field_checkbox = $('.form-item-instance-required .form-checkbox', context);
+ if ($required_field_checkbox.length) {
+ // Get the permissions table row corresponding to the "Create own value
+ // for field X" permission. The theme_user_admin_permissions() function
+ // does not give us a good way to directly detect which row contains
+ // the create permissions, so we have rely on the fact that it will be
+ // the first row.
+ $create_permission_row = $('table#permissions tbody tr', context).filter(':first');
+ new Drupal.fieldPermissions.HideCreatePermission($user_register_form_checkbox, $required_field_checkbox, $create_permission_row);
+ }
}
+
+ // Show a warning if there's no available permissions matrix.
+ $('#edit-field-field-permissions-permission-warning').toggle(!$('#permissions').length);
+
+ $('[name="field[field_permissions][type]"]').bind('change', function(option) {
+ $('#edit-field-field-permissions-permission-warning').toggle(!$('#permissions').length);
+ });
}
- }
-};
+ };
-Drupal.fieldPermissions = {};
+ Drupal.fieldPermissions = {};
-/**
+ /**
* Constructor for the HideCreatePermission object.
*
* This object hides and shows the "Create own value for field X" permission
* for user fields when it is appropriate to do so, depending on the state of
* the "Display on user registration form" and "Required field" checkboxes.
*/
-Drupal.fieldPermissions.HideCreatePermission = function ($user_register_form_checkbox, $required_field_checkbox, $create_permission_row) {
- this.$user_register_form_checkbox = $user_register_form_checkbox;
- this.$create_permission_row = $create_permission_row;
- // Start off by making sure the create permission row has the correct
- // visibility.
- this.setCreatePermissionVisibility();
- // Set the row's visibility again whenever the user registration checkbox
- // changes, or when the required field checkbox (which controls it) changes.
- $user_register_form_checkbox.bind('change', $.proxy(this.setCreatePermissionVisibility, this));
- $required_field_checkbox.bind('change', $.proxy(this.setCreatePermissionVisibility, this));
-};
+ Drupal.fieldPermissions.HideCreatePermission = function ($user_register_form_checkbox, $required_field_checkbox, $create_permission_row) {
+ this.$user_register_form_checkbox = $user_register_form_checkbox;
+ this.$create_permission_row = $create_permission_row;
+ // Start off by making sure the create permission row has the correct
+ // visibility.
+ this.setCreatePermissionVisibility();
+ // Set the row's visibility again whenever the user registration checkbox
+ // changes, or when the required field checkbox (which controls it) changes.
+ $user_register_form_checkbox.bind('change', $.proxy(this.setCreatePermissionVisibility, this));
+ $required_field_checkbox.bind('change', $.proxy(this.setCreatePermissionVisibility, this));
+ };
-/**
- * Set the correct visibility of the "Create own value for field X" permission.
- */
-Drupal.fieldPermissions.HideCreatePermission.prototype.setCreatePermissionVisibility = function () {
- // Granting permissions for "Create own value for field X" only makes sense
- // when the field is configured to appear on the user registration form, so
- // only show the row in the permissions table then.
- if (this.$user_register_form_checkbox.is(':checked')) {
- this.$create_permission_row.show();
- }
- else {
- this.$create_permission_row.hide();
- }
-};
+ /**
+ * Set the correct visibility of the "Create own value for field X" permission.
+ */
+ Drupal.fieldPermissions.HideCreatePermission.prototype.setCreatePermissionVisibility = function () {
+ // Granting permissions for "Create own value for field X" only makes sense
+ // when the field is configured to appear on the user registration form, so
+ // only show the row in the permissions table then.
+ if (this.$user_register_form_checkbox.is(':checked')) {
+ this.$create_permission_row.show();
+ }
+ else {
+ this.$create_permission_row.hide();
+ }
+ };
})(jQuery);
diff --git a/sites/all/modules/contrib/admin/field_permissions/field_permissions.api.php b/sites/all/modules/contrib/admin/field_permissions/field_permissions.api.php
new file mode 100644
index 00000000..3379c7ad
--- /dev/null
+++ b/sites/all/modules/contrib/admin/field_permissions/field_permissions.api.php
@@ -0,0 +1,85 @@
+uid.
+ * @param object $entity
+ * The entity this field belongs to.
+ */
+// @codingStandardsIgnoreStart
+function hook_field_permissions_userid_ENTITY_TYPE_alter(&$uid, $entity) {
+ // This example always assigns user 15 as the owner of an entity.
+ $uid = 15;
+}
+// @codingStandardsIgnoreEnd
+
+/**
+ * Alter the permissions handled by field_permissions module.
+ *
+ * @param array $permissions
+ * The $permissions array created by the Field permissions module.
+ * @param string $field_label
+ * The field name.
+ */
+function hook_field_permissions_list_alter(&$permissions, $field_label) {
+ $permissions += array(
+ 'view own node preview' => array(
+ 'label' => t('View own field on node preview'),
+ 'title' => t('View own value for field %field on node preview', array('%field' => $field_label)),
+ ),
+ 'view node preview' => array(
+ 'label' => t('View field on node preview'),
+ 'title' => t("View anyone's value for field %field on node preview", array('%field' => $field_label)),
+ ),
+ );
+}
+
+/**
+ * Hook invoked with custom field permissions.
+ *
+ * This hook can be used to revoke access to the field. If access is not
+ * revoked, default access of the Field permissions module will apply.
+ *
+ * @param string $op
+ * The operation to be performed. Possible values: 'edit', 'view'.
+ * @param array $field
+ * The field on which the operation is to be performed.
+ * @param string $entity_type
+ * The type of $entity; for example, 'node' or 'user'.
+ * @param object $entity
+ * (optional) The entity for the operation.
+ * @param object $account
+ * (optional) The account to check; if not given use currently logged in user.
+ *
+ * @return bool
+ * FALSE if the operation is not allowed.
+ *
+ * @see field_permissions_field_access()
+ * @see field_access()
+ */
+function hook_field_permissions_custom_field_access($op, $field, $entity_type, $entity, $account) {
+ if ($op == 'view' && $entity_type == 'node' && !empty($entity)) {
+ // Check if user has access to view this field in any entity.
+ if (!user_access('view node preview ' . $field['field_name'], $account)) {
+ return FALSE;
+ }
+
+ // If the user has permission to view entities that they own, return TRUE if
+ // they own this entity or FALSE if they don't.
+ if (user_access('view own node preview ' . $field['field_name'], $account)) {
+ return _field_permissions_entity_is_owned_by_account($entity, $account);
+ }
+ }
+
+ return TRUE;
+}
diff --git a/sites/all/modules/contrib/admin/field_permissions/field_permissions.info b/sites/all/modules/contrib/admin/field_permissions/field_permissions.info
index cdb9f171..ffd9f66f 100644
--- a/sites/all/modules/contrib/admin/field_permissions/field_permissions.info
+++ b/sites/all/modules/contrib/admin/field_permissions/field_permissions.info
@@ -2,14 +2,12 @@ name = Field Permissions
description = Set field-level permissions to create, update or view fields.
package = Fields
core = 7.x
-files[] = field_permissions.module
-files[] = field_permissions.admin.inc
files[] = field_permissions.test
configure = admin/reports/fields/permissions
-; Information added by drupal.org packaging script on 2012-01-25
-version = "7.x-1.0-beta2"
+; Information added by Drupal.org packaging script on 2016-10-15
+version = "7.x-1.0-beta2+21-dev"
core = "7.x"
project = "field_permissions"
-datestamp = "1327510549"
+datestamp = "1476570240"
diff --git a/sites/all/modules/contrib/admin/field_permissions/field_permissions.install b/sites/all/modules/contrib/admin/field_permissions/field_permissions.install
index 2e3e1981..e4fac9a3 100644
--- a/sites/all/modules/contrib/admin/field_permissions/field_permissions.install
+++ b/sites/all/modules/contrib/admin/field_permissions/field_permissions.install
@@ -16,6 +16,28 @@ function field_permissions_install() {
->execute();
}
+/**
+ * Implements hook_uninstall().
+ */
+function field_permissions_uninstall() {
+
+ // Collect all the field data that reference "field_permissions", within
+ // the field_config table.
+ //
+ $records = db_query("SELECT * FROM field_config WHERE data LIKE '%field_permissions%'");
+
+ foreach ($records as $record) {
+ $data = $record->data;
+ $data = unserialize($data);
+ unset($data['field_permissions']);
+ $data = serialize($data);
+
+ // Update the record.
+ db_query("UPDATE field_config SET data = :data WHERE id = :id",
+ array(':data' => $data, ':id' => $record->id));
+ }
+}
+
/**
* Sets a larger weight for the module so that the Field Permissions become available.
*/
diff --git a/sites/all/modules/contrib/admin/field_permissions/field_permissions.module b/sites/all/modules/contrib/admin/field_permissions/field_permissions.module
index bc4d1f5d..ea5667ec 100644
--- a/sites/all/modules/contrib/admin/field_permissions/field_permissions.module
+++ b/sites/all/modules/contrib/admin/field_permissions/field_permissions.module
@@ -79,6 +79,13 @@ function field_permissions_form_field_ui_field_edit_form_alter(&$form, &$form_st
return _field_permissions_field_settings_form_alter($form, $form_state, $form_id);
}
+/**
+ * Implements hook_field_permissions_userid_ENTITY_TYPE_alter().
+ */
+function field_permissions_field_permissions_userid_field_collection_item_alter(&$uid, $entity) {
+ $uid = isset($entity->hostEntity()->uid) ? $entity->hostEntity()->uid : $uid;
+}
+
/**
* Implementation of hook_field_access().
*
@@ -124,6 +131,12 @@ function field_permissions_field_access($op, $field, $entity_type, $entity, $acc
}
// Otherwise, check access by permission.
elseif ($field['field_permissions']['type'] == FIELD_PERMISSIONS_CUSTOM) {
+ // Allow other modules to deny access first.
+ $result = module_invoke_all('field_permissions_custom_field_access', $op, $field, $entity_type, $entity, $account);
+ if (in_array(FALSE, $result)) {
+ return FALSE;
+ }
+
if (!isset($entity)) {
return field_permissions_empty_entity_access($op, $field['field_name'], $account);
}
@@ -258,5 +271,76 @@ function _field_permissions_entity_is_owned_by_account($entity, $account) {
// set (for example, if the entity type does not store a uid or does not have
// a concept of "ownership"), we need to assume that the provided user
// account does not own it.
- return isset($entity->uid) && $entity->uid == $account->uid;
+ $uid = isset($entity->uid) ? $entity->uid : FALSE;
+ if (method_exists($entity, 'entityType')) {
+ drupal_alter('field_permissions_userid_' . $entity->entityType(), $uid, $entity);
+ }
+
+ return $uid === $account->uid;
+}
+
+/**
+ * Implements hook_features_pipe_COMPONENT_alter().
+ *
+ * Add field permissions to features when exporting a field_base.
+ */
+function field_permissions_features_pipe_field_base_alter(&$pipe, $data, $export) {
+ // Validate if there are field_base components that will be exported for this
+ // feature.
+ if (isset($export['features']['field_base'])) {
+ module_load_include('inc', 'field_permissions', 'field_permissions.admin');
+ // Iterate through the exported field_base components for this feature and
+ // add the defined field permissions.
+ foreach ($export['features']['field_base'] as $field_name) {
+ $field = field_info_field($field_name);
+ if (isset($field['field_permissions']['type']) && $field['field_permissions']['type'] == FIELD_PERMISSIONS_CUSTOM) {
+ $perms = field_permissions_list_field_permissions($field, '');
+ foreach ($perms as $perm => $info) {
+ $pipe['user_permission'][] = $perm;
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Implements hook_field_attach_form().
+ */
+function field_permissions_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
+ // Some fields are validated if they are #required even if field's #access
+ // property is set to false. For example: file/image fields, options fields.
+ foreach (element_children($form) as $key) {
+ if (isset($form[$key]['#access']) && !$form[$key]['#access']) {
+ _field_permissions_make_elements_non_required($form[$key]);
+ }
+ }
+}
+
+/**
+ * Sets the #required property to FALSE recursively on form elements.
+ */
+function _field_permissions_make_elements_non_required(&$elements) {
+ if (!is_array($elements)) {
+ return;
+ }
+ if (!empty($elements['#required'])) {
+ $elements['#required'] = FALSE;
+ }
+ foreach (element_children($elements) as $key) {
+ _field_permissions_make_elements_non_required($elements[$key]);
+ }
+}
+
+/**
+ * Implements hook_field_delete_field().
+ */
+function field_permissions_field_delete_field($field) {
+ // Delete any permissions related to the deleted field.
+ $all_permissions = array_keys(field_permissions_permission());
+ if (!empty($all_permissions)) {
+ db_delete('role_permission')
+ ->condition('module', 'field_permissions')
+ ->condition('permission', $all_permissions, 'NOT IN')
+ ->execute();
+ }
}
diff --git a/sites/all/modules/contrib/admin/field_permissions/field_permissions.test b/sites/all/modules/contrib/admin/field_permissions/field_permissions.test
index 201fa460..c5f85447 100644
--- a/sites/all/modules/contrib/admin/field_permissions/field_permissions.test
+++ b/sites/all/modules/contrib/admin/field_permissions/field_permissions.test
@@ -26,7 +26,7 @@ class FieldPermissionsTestCase extends DrupalWebTestCase {
parent::setUp('field_ui', 'field_permissions');
// Create test user.
- $admin_permissions = array('access content', 'administer nodes', 'bypass node access', 'administer content types', 'administer taxonomy', 'administer permissions', 'create page content');
+ $admin_permissions = array('access content', 'administer nodes', 'bypass node access', 'administer content types', 'administer taxonomy', 'administer permissions', 'create page content', 'administer fields');
$this->limited_user = $this->drupalCreateUser($admin_permissions);
$all_rids = array_keys($this->limited_user->roles);
sort($all_rids);
@@ -162,11 +162,11 @@ class FieldPermissionsTestCase extends DrupalWebTestCase {
// See if we have that exposed on the permissions UI as well now.
$this->drupalGet('admin/people/permissions');
$this->assertText(t('Field Permissions'));
- $this->assertRaw(t('Create own value for field %field', array('%field' => $field_info['name'])));
- $this->assertRaw(t('Edit own value for field %field', array('%field' => $field_info['name'])));
- $this->assertRaw(t("Edit anyone's value for field %field", array('%field' => $field_info['name'])));
- $this->assertRaw(t('View own value for field %field', array('%field' => $field_info['name'])));
- $this->assertRaw(t("View anyone's value for field %field", array('%field' => $field_info['name'])));
+ $this->assertRaw(t('Create own value for field %field', array('%field' => $field_info['machine_name'])));
+ $this->assertRaw(t('Edit own value for field %field', array('%field' => $field_info['machine_name'])));
+ $this->assertRaw(t("Edit anyone's value for field %field", array('%field' => $field_info['machine_name'])));
+ $this->assertRaw(t('View own value for field %field', array('%field' => $field_info['machine_name'])));
+ $this->assertRaw(t("View anyone's value for field %field", array('%field' => $field_info['machine_name'])));
// == CREATE ===============================================================
diff --git a/sites/all/modules/contrib/fields/field_collection/LICENSE.txt b/sites/all/modules/contrib/fields/field_collection/LICENSE.txt
deleted file mode 100644
index d159169d..00000000
--- a/sites/all/modules/contrib/fields/field_collection/LICENSE.txt
+++ /dev/null
@@ -1,339 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- , 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.
diff --git a/sites/all/modules/contrib/fields/field_collection/README.txt b/sites/all/modules/contrib/fields/field_collection/README.txt
deleted file mode 100644
index c611bddb..00000000
--- a/sites/all/modules/contrib/fields/field_collection/README.txt
+++ /dev/null
@@ -1,46 +0,0 @@
-Field collection
------------------
-Provides a field collection field, to which any number of fields can be attached.
-
-Each field collection item is internally represented as an entity, which is
-referenced via the field collection field in the host entity. While
-conceptually field collections are treated as part of the host entity, each
-field collection item may also be viewed and edited separately.
-
-
- Usage
- ------
-
- * Add a field collection field to any entity, e.g. to a node. For that use the
- the usual "Manage fields" interface provided by the "field ui" module of
- Drupal, e.g. "Admin -> Structure-> Content types -> Article -> Manage fields".
-
- * Then go to "Admin -> Structure-> Field collection" to define some fields for
- the created field collection.
-
- * By the default, the field collection is not shown during editing of the host
- entity. However, some links for adding, editing or deleting field collection
- items is shown when the host entity is viewed.
-
- * Widgets for embedding the form for creating field collections in the
- host-entity can be provided by any module. In future the field collection
- module might provide such widgets itself too.
-
-
- Using field collection with entity translation
- -----------------------------------------------
-
- * Field collection items must be selected as a translatable entity type at
- Admin -> Config -> Regional -> Entity Translation.
-
- * The common use case is to leave the field collection field untranslatable
- and set the necessary fields inside it to translatable. There is currently
- a known issue where a host can not be translated unless it has at least
- one other field that is translatable, even if some fields inside one of
- its field collections are translatable.
-
- * The alternate use case is to make the field collection field in the host
- translatable. If this is done it does not matter whether the inner fields
- are set to translatable or not, they will all be translatable as every
- language for the host will have a completely separate copy of the field
- collection item(s).
diff --git a/sites/all/modules/contrib/fields/field_collection/ctools/relationships/field_collection_from_field.inc b/sites/all/modules/contrib/fields/field_collection/ctools/relationships/field_collection_from_field.inc
deleted file mode 100644
index 58d970c5..00000000
--- a/sites/all/modules/contrib/fields/field_collection/ctools/relationships/field_collection_from_field.inc
+++ /dev/null
@@ -1,106 +0,0 @@
- t('Field collection item'),
- 'description' => t('Creates an entity context from a field collection field on a field.'),
- 'context' => 'field_collection_field_collection_from_field_context',
- 'edit form' => 'field_collection_field_collection_from_field_edit_form',
- 'get child' => 'field_collection_field_collection_from_field_get_child',
- 'get children' => 'field_collection_field_collection_from_field_get_children',
- 'defaults' => array('delta' => 0),
-);
-
-/**
- * Get child callback.
- */
-function field_collection_field_collection_from_field_get_child($plugin, $parent, $child) {
- $plugins = field_collection_field_collection_from_field_get_children($plugin, $parent);
- return $plugins[$parent . ':' . $child];
-}
-
-/**
- * Get children callback.
- */
-function field_collection_field_collection_from_field_get_children($plugin, $parent) {
-
- $plugins = array();
- $instances_info = field_info_instances();
- if (isset($instances_info['field_collection_item'])) {
- $field_collection_items = $instances_info['field_collection_item'];
-
- foreach (field_read_instances() as $instance) {
- if (isset($field_collection_items[$instance['field_name']])) {
- $child_plugin_id = $parent . ':' . $instance['entity_type'] . ':' . $instance['bundle'] . ':' . $instance['field_name'];
-
- $child_plugin = $plugin;
- $child_plugin['context name'] = $instance['entity_type'] . ':' . $instance['bundle'] . ':' . $instance['field_name'];
- $child_plugin['title'] = t(
- '!label field collection (!field_name) from !entity_type (!bundle)',
- array(
- '!label' => $instance['label'],
- '!field_name' => $instance['field_name'],
- '!entity_type' => $instance['entity_type'],
- '!bundle' => $instance['bundle']
- )
- );
- $restrictions = array('type' => array($instance['bundle']));
- $child_plugin['required context'] = new ctools_context_required(ucfirst($instance['entity_type']), $instance['entity_type'], $restrictions);
- $child_plugin['parent'] = $parent;
- $child_plugin['keyword'] = 'Field collection';
- $child_plugin['entity_type'] = $instance['entity_type'];
- $child_plugin['field_name'] = $instance['field_name'];
-
- $child_plugin['name'] = $child_plugin_id;
- $plugins[$child_plugin_id] = $child_plugin;
-
- }
- }
- }
-
- return $plugins;
-}
-
-/**
- * Return a new field collection context based on an existing context.
- */
-function field_collection_field_collection_from_field_context($context, $conf) {
-
- $plugin_info = ctools_get_relationship($conf['name']);
- $delta = (int) $conf['delta'];
-
- $entity = $context->data;
- if (isset($entity->{$plugin_info['field_name']})) {
-
- $items = field_get_items($plugin_info['entity_type'], $entity, $plugin_info['field_name']);
- if (isset($items[$delta]['value'])) {
- $field_collection_item = field_collection_item_load($items[$delta]['value']);
- }
-
- return ctools_context_create('entity:field_collection_item', $items[$delta]['value']);
- }
-
- return ctools_context_create_empty('entity:field_collection_item', NULL);
-}
-
-/**
- * Settings form.
- */
-function field_collection_field_collection_from_field_edit_form($form, &$form_state) {
- $conf = $form_state['conf'];
-
- $form['delta'] = array(
- '#type' => 'textfield',
- '#title' => t('Delta'),
- '#size' => 3,
- '#description' => t('The relationship can only create one context, but multiple items can be related. Please type in the number you want. The first one will be 0.'),
- '#default_value' => empty($conf['delta']) ? 0 : $conf['delta'],
- );
-
- return $form;
-}
diff --git a/sites/all/modules/contrib/fields/field_collection/field-collection-item.tpl.php b/sites/all/modules/contrib/fields/field_collection/field-collection-item.tpl.php
deleted file mode 100644
index 8d345cb6..00000000
--- a/sites/all/modules/contrib/fields/field_collection/field-collection-item.tpl.php
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
>
-
>
-
-
-
diff --git a/sites/all/modules/contrib/fields/field_collection/field_collection.admin.inc b/sites/all/modules/contrib/fields/field_collection/field_collection.admin.inc
deleted file mode 100644
index b6328a44..00000000
--- a/sites/all/modules/contrib/fields/field_collection/field_collection.admin.inc
+++ /dev/null
@@ -1,47 +0,0 @@
- t('Operations'), 'colspan' => '2'));
- $rows = array();
- foreach ($instances as $entity_type => $type_bundles) {
- foreach ($type_bundles as $bundle => $bundle_instances) {
- foreach ($bundle_instances as $field_name => $instance) {
- $field = field_info_field($field_name);
- if ($field['type'] == 'field_collection') {
- $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
- $rows[$field_name]['class'] = $field['locked'] ? array('menu-disabled') : array('');
-
- $rows[$field_name]['data'][0] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name;
- $rows[$field_name]['data'][1][] = l($bundles[$entity_type][$bundle]['label'], $admin_path . '/fields');
- }
- }
- }
- }
- foreach ($rows as $field_name => $cell) {
- $rows[$field_name]['data'][1] = implode(', ', $cell['data'][1]);
-
- $field_name_url_str = strtr($field_name, array('_' => '-'));
- $rows[$field_name]['data'][2] = l(t('manage fields'), 'admin/structure/field-collections/' . $field_name_url_str . '/fields');
- $rows[$field_name]['data'][3] = l(t('manage display'), 'admin/structure/field-collections/' . $field_name_url_str . '/display');
- }
- if (empty($rows)) {
- $output = t('No field collections have been defined yet. To do so attach a field collection field to any entity.');
- }
- else {
- // Sort rows by field name.
- ksort($rows);
- $output = theme('table', array('header' => $header, 'rows' => $rows));
- }
- return $output;
-}
diff --git a/sites/all/modules/contrib/fields/field_collection/field_collection.api.php b/sites/all/modules/contrib/fields/field_collection/field_collection.api.php
deleted file mode 100644
index a2c87171..00000000
--- a/sites/all/modules/contrib/fields/field_collection/field_collection.api.php
+++ /dev/null
@@ -1,195 +0,0 @@
-my_field) && empty($item->my_field)) {
- $is_empty = TRUE;
- }
-}
-
-/**
- * Acts on field collections being loaded from the database.
- *
- * This hook is invoked during field collection item loading, which is handled
- * by entity_load(), via the EntityCRUDController.
- *
- * @param array $entities
- * An array of field collection item entities being loaded, keyed by id.
- *
- * @see hook_entity_load()
- */
-function hook_field_collection_item_load(array $entities) {
- $result = db_query('SELECT pid, foo FROM {mytable} WHERE pid IN(:ids)', array(':ids' => array_keys($entities)));
- foreach ($result as $record) {
- $entities[$record->pid]->foo = $record->foo;
- }
-}
-
-/**
- * Responds when a field collection item is inserted.
- *
- * This hook is invoked after the field collection item is inserted into the
- * database.
- *
- * @param FieldCollectionItemEntity $field_collection_item
- * The field collection item that is being inserted.
- *
- * @see hook_entity_insert()
- */
-function hook_field_collection_item_insert(FieldCollectionItemEntity $field_collection_item) {
- db_insert('mytable')->fields(array(
- 'id' => entity_id('field_collection_item', $field_collection_item),
- 'extra' => print_r($field_collection_item, TRUE),
- ))->execute();
-}
-
-/**
- * Acts on a field collection item being inserted or updated.
- *
- * This hook is invoked before the field collection item is saved to the database.
- *
- * @param FieldCollectionItemEntity $field_collection_item
- * The field collection item that is being inserted or updated.
- *
- * @see hook_entity_presave()
- */
-function hook_field_collection_item_presave(FieldCollectionItemEntity $field_collection_item) {
- $field_collection_item->name = 'foo';
-}
-
-/**
- * Responds to a field collection item being updated.
- *
- * This hook is invoked after the field collection item has been updated in the
- * database.
- *
- * @param FieldCollectionItemEntity $field_collection_item
- * The field collection item that is being updated.
- *
- * @see hook_entity_update()
- */
-function hook_field_collection_item_update(FieldCollectionItemEntity $field_collection_item) {
- db_update('mytable')
- ->fields(array('extra' => print_r($field_collection_item, TRUE)))
- ->condition('id', entity_id('field_collection_item', $field_collection_item))
- ->execute();
-}
-
-/**
- * Responds to field collection item deletion.
- *
- * This hook is invoked after the field collection item has been removed from
- * the database.
- *
- * @param FieldCollectionItemEntity $field_collection_item
- * The field collection item that is being deleted.
- *
- * @see hook_entity_delete()
- */
-function hook_field_collection_item_delete(FieldCollectionItemEntity $field_collection_item) {
- db_delete('mytable')
- ->condition('pid', entity_id('field_collection_item', $field_collection_item))
- ->execute();
-}
-
-/**
- * Act on a field collection item that is being assembled before rendering.
- *
- * @param $field_collection_item
- * The field collection item entity.
- * @param $view_mode
- * The view mode the field collection item is rendered in.
- * @param $langcode
- * The language code used for rendering.
- *
- * The module may add elements to $field_collection_item->content prior to
- * rendering. The structure of $field_collection_item->content is a renderable
- * array as expected by drupal_render().
- *
- * @see hook_entity_prepare_view()
- * @see hook_entity_view()
- */
-function hook_field_collection_item_view($field_collection_item, $view_mode, $langcode) {
- $field_collection_item->content['my_additional_field'] = array(
- '#markup' => $additional_field,
- '#weight' => 10,
- '#theme' => 'mymodule_my_additional_field',
- );
-}
-
-/**
- * Alter the results of entity_view() for field collection items.
- *
- * This hook is called after the content has been assembled in a structured
- * array and may be used for doing processing which requires that the complete
- * field collection item content structure has been built.
- *
- * If the module wishes to act on the rendered HTML of the field collection item
- * rather than the structured content array, it may use this hook to add a
- * #post_render callback. See drupal_render() and theme() documentation
- * respectively for details.
- *
- * @param $build
- * A renderable array representing the field collection item content.
- *
- * @see hook_entity_view_alter()
- */
-function hook_field_collection_item_view_alter($build) {
- if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
- // Change its weight.
- $build['an_additional_field']['#weight'] = -10;
-
- // Add a #post_render callback to act on the rendered HTML of the entity.
- $build['#post_render'][] = 'my_module_post_render';
- }
-}
-
-/**
- * Alter the label for a field collection.
- *
- * @param FieldCollectionItemEntity $item
- * The field collection item object.
- * @param $host
- * The host entity of the field collection item.
- * @param $field
- * The field information about the item.
- *
- * @return $label
- * A string to represent the label for this item type.
- */
-function hook_field_collection_item_label($item, $host, $field) {
- switch ($item->field_name) {
- case 'field_my_first_collection':
- $item_wrapper = entity_metadata_wrapper('field_collection_item', $item);
-
- $title = $item_wrapper->field_title->value();
- $author = $item_wrapper->field_author->value();
-
- return "{$title} by {$author}";
- }
-}
-
-
-/**
- * @}
- */
diff --git a/sites/all/modules/contrib/fields/field_collection/field_collection.diff.inc b/sites/all/modules/contrib/fields/field_collection/field_collection.diff.inc
deleted file mode 100644
index 0ce413d8..00000000
--- a/sites/all/modules/contrib/fields/field_collection/field_collection.diff.inc
+++ /dev/null
@@ -1,93 +0,0 @@
- $item) {
- $diff_items[$delta] = field_collection_field_render_revision($item, $context);
- }
- return $diff_items;
-}
-
-/**
- * Renders a field collection fields revision.
- */
-function field_collection_field_render_revision($item, $context) {
- $entity_type = 'field_collection_item';
- $bundle_name = $context['field']['field_name'];
- $view_mode = $context['view_mode'];
- $entity = entity_revision_load($entity_type, $item['revision_id']);
-
- $field_context = $context;
- $field_context['entity_type'] = $entity_type;
- $field_context['bundle'] = $bundle_name;
- $field_context['entity'] = $entity;
-
- // Some fields piggy back the display settings, so we need to fake these by
- // ensuring that the field mode is always set.
- if (empty($view_mode)) {
- $field_context['custom_settings'] = FALSE;
- }
- $view_mode_settings = field_view_mode_settings($entity_type, $bundle_name);
- $actual_mode = (!empty($view_mode_settings[$view_mode]['custom_settings'])) ? $view_mode : 'default';
- if (!isset($field_context['custom_settings'])) {
- $field_context['custom_settings'] = $actual_mode && $actual_mode == $view_mode;
- }
-
- $instances = field_info_instances($entity_type, $field_context['bundle']);
- usort($instances, '_field_collection_sort_items');
-
- $result = array();
- foreach ($instances as $instance) {
- // Any view mode is supported in relation to hiding fields, but only if selected.
- if ($actual_mode && $instance['display'][$actual_mode]['type'] == 'hidden') {
- continue;
- }
-
- $field_name = $instance['field_name'];
- $field = field_info_field($field_name);
-
- // We provide a loose check on the field access.
- if (field_access('view', $field, $entity_type) || field_access('edit', $field, $entity_type)) {
- $langcode = field_language($entity_type, $entity, $field_name);
- $field_context['language'] = $langcode;
- $field_context['field'] = $field;
- $field_context['instance'] = $instance;
- $field_context['settings'] = diff_get_field_settings($field_context);
- $field_context['display'] = $instance['display'][$actual_mode];
-
- $func = $field['module'] . '_field_diff_view';
- if (!function_exists($func)) {
- $func = 'diff_field_diff_view';
- }
-
- if (!empty($entity->{$field_name}[$langcode])) {
- $raw_values = $func($entity->{$field_name}[$langcode], $field_context);
- $values = array();
- foreach ($raw_values as $raw_value) {
- $values[] = is_array($raw_value) ? implode(", ", $raw_value) : $raw_value;
- }
-
- $result[] = check_plain($instance['label'] . ': ' . implode(", ", $values));
- }
- }
- }
-
- return $result;
-}
-
-/**
- * Sort function for items order.
- */
-function _field_collection_sort_items($a, $b) {
- $a_weight = (!empty($a['widget']['weight']) ? $a['widget']['weight'] : 0);
- $b_weight = (!empty($b['widget']['weight']) ? $b['widget']['weight'] : 0);
- return $a_weight - $b_weight;
-}
diff --git a/sites/all/modules/contrib/fields/field_collection/field_collection.entity.inc b/sites/all/modules/contrib/fields/field_collection/field_collection.entity.inc
deleted file mode 100644
index 9369bc4e..00000000
--- a/sites/all/modules/contrib/fields/field_collection/field_collection.entity.inc
+++ /dev/null
@@ -1,629 +0,0 @@
-field_name)) {
- // Ok, we have the field name property, we can proceed and check the field's type
- $field_info = $this->fieldInfo();
- if (!$field_info || $field_info['type'] != 'field_collection') {
- throw new Exception("Invalid field name given: {$this->field_name} is not a Field Collection field.");
- }
- }
- }
-
- /**
- * Provides info about the field on the host entity, which embeds this
- * field collection item.
- */
- public function fieldInfo() {
- return field_info_field($this->field_name);
- }
-
- /**
- * Provides info of the field instance containing the reference to this
- * field collection item.
- */
- public function instanceInfo() {
- if ($this->fetchHostDetails()) {
- return field_info_instance($this->hostEntityType(), $this->field_name, $this->hostEntityBundle());
- }
- }
-
- /**
- * Returns the field instance label translated to interface language.
- */
- public function translatedInstanceLabel($langcode = NULL) {
- if ($info = $this->instanceInfo()) {
- if (module_exists('i18n_field')) {
- return i18n_string("field:{$this->field_name}:{$info['bundle']}:label", $info['label'], array('langcode' => $langcode));
- }
- return $info['label'];
- }
- }
-
- /**
- * Specifies the default label, which is picked up by label() by default.
- */
- public function defaultLabel() {
- if ($this->fetchHostDetails()) {
- $field = $this->fieldInfo();
- $label = $this->translatedInstanceLabel();
- $host = $this->hostEntity();
-
- if ($new_label = module_invoke_all('field_collection_item_label', $this, $host, $field, $label)) {
- return array_pop($new_label);
- }
- elseif ($field['cardinality'] == 1) {
- return $label;
- }
- elseif ($this->item_id) {
- return t('!instance_label @count', array('!instance_label' => $label, '@count' => $this->delta() + 1));
- }
- else {
- return t('New !instance_label', array('!instance_label' => $label));
- }
- }
- return t('Unconnected field collection item');
- }
-
- /**
- * Returns the path used to view the entity.
- */
- public function path() {
- if ($this->item_id) {
- return field_collection_field_get_path($this->fieldInfo()) . '/' . $this->item_id;
- }
- }
-
- /**
- * Returns the URI as returned by entity_uri().
- */
- public function defaultUri() {
- return array(
- 'path' => $this->path(),
- );
- }
-
- /**
- * Sets the host entity. Only possible during creation of a item.
- *
- * @param $create_link
- * (optional) Whether a field-item linking the host entity to the field
- * collection item should be created.
- */
- public function setHostEntity($entity_type, $entity, $langcode = LANGUAGE_NONE, $create_link = TRUE) {
- if (!empty($this->is_new)) {
- $this->hostEntityType = $entity_type;
- $this->hostEntity = $entity;
- $this->langcode = $langcode;
-
- list($this->hostEntityId, $this->hostEntityRevisionId) = entity_extract_ids($this->hostEntityType, $this->hostEntity);
- // If the host entity is not saved yet, set the id to FALSE. So
- // fetchHostDetails() does not try to load the host entity details.
- if (!isset($this->hostEntityId)) {
- $this->hostEntityId = FALSE;
- }
- // We are create a new field collection for a non-default entity, thus
- // set archived to TRUE.
- if (!entity_revision_is_default($entity_type, $entity)) {
- $this->hostEntityId = FALSE;
- $this->archived = TRUE;
- }
- if ($create_link) {
- $entity->{$this->field_name}[$this->langcode][] = array('entity' => $this);
- }
- }
- else {
- throw new Exception('The host entity may be set only during creation of a field collection item.');
- }
- }
-
- /**
- * Updates the wrapped host entity object.
- *
- * @param object $entity
- * Host entity.
- * @param string $host_entity_type
- * The entity type of the entity the field collection is attached to.
- */
- public function updateHostEntity($entity, $host_entity_type = NULL) {
- $this->fetchHostDetails();
- // If it isn't possible to retrieve hostEntityType due to the fact that it's
- // not saved in the DB yet then fill in info about the hostEntity manually.
- // This happens when creating a new revision of a field collection entity
- // and it needs to relate to the new revision of the host entity.
- if (!$this->hostEntityType) {
- $this->hostEntityType = $host_entity_type;
- $this->hostEntity = $entity;
- list($this->hostEntityId, $this->hostEntityRevisionId) = entity_extract_ids($this->hostEntityType, $this->hostEntity);
- }
- list($recieved_id) = entity_extract_ids($this->hostEntityType, $entity);
-
- if ($this->isInUse()) {
- $current_id = $this->hostEntityId;
- }
- else {
- $current_host = entity_revision_load($this->hostEntityType, $this->hostEntityRevisionId);
- list($current_id) = entity_extract_ids($this->hostEntityType, $current_host);
- }
-
- if ($current_id == $recieved_id) {
- $this->hostEntity = $entity;
- $delta = $this->delta();
- if (isset($entity->{$this->field_name}[$this->langcode()][$delta]['entity'])) {
- $entity->{$this->field_name}[$this->langcode()][$delta]['entity'] = $this;
- }
- }
- else {
- throw new Exception('The host entity cannot be changed.');
- }
- }
-
- /**
- * Returns the host entity, which embeds this field collection item.
- */
- public function hostEntity() {
- if ($this->fetchHostDetails()) {
- if (!isset($this->hostEntity) && $this->isInUse()) {
- $this->hostEntity = entity_load_single($this->hostEntityType, $this->hostEntityId);
- }
- elseif (!isset($this->hostEntity) && $this->hostEntityRevisionId) {
- $this->hostEntity = entity_revision_load($this->hostEntityType, $this->hostEntityRevisionId);
- }
- return $this->hostEntity;
- }
- }
-
- /**
- * Returns the entity type of the host entity, which embeds this
- * field collection item.
- */
- public function hostEntityType() {
- if ($this->fetchHostDetails()) {
- return $this->hostEntityType;
- }
- }
-
- /**
- * Returns the id of the host entity, which embeds this field collection item.
- */
- public function hostEntityId() {
- if ($this->fetchHostDetails()) {
- if (!$this->hostEntityId && $this->hostEntityRevisionId) {
- $this->hostEntityId = entity_id($this->hostEntityType, $this->hostEntity());
- }
- return $this->hostEntityId;
- }
- }
-
- /**
- * Returns the bundle of the host entity, which embeds this field collection
- * item.
- */
- public function hostEntityBundle() {
- if ($entity = $this->hostEntity()) {
- list($id, $rev_id, $bundle) = entity_extract_ids($this->hostEntityType, $entity);
- return $bundle;
- }
- }
-
- protected function fetchHostDetails() {
- if (!isset($this->hostEntityId)) {
- if ($this->item_id) {
- // For saved field collections, query the field data to determine the
- // right host entity.
- $query = new EntityFieldQuery();
- $query->fieldCondition($this->fieldInfo(), 'revision_id', $this->revision_id);
- if (!$this->isInUse()) {
- $query->age(FIELD_LOAD_REVISION);
- }
- $result = $query->execute();
- list($this->hostEntityType, $data) = each($result);
-
- if ($this->isInUse()) {
- $this->hostEntityId = $data ? key($data) : FALSE;
- $this->hostEntityRevisionId = FALSE;
- }
- // If we are querying for revisions, we get the revision ID.
- else {
- $this->hostEntityId = FALSE;
- $this->hostEntityRevisionId = $data ? key($data) : FALSE;
- }
- }
- else {
- // No host entity available yet.
- $this->hostEntityId = FALSE;
- }
- }
- return !empty($this->hostEntityId) || !empty($this->hostEntity) || !empty($this->hostEntityRevisionId);
- }
-
- /**
- * Determines the $delta of the reference pointing to this field collection
- * item.
- */
- public function delta() {
- if (($entity = $this->hostEntity()) && isset($entity->{$this->field_name})) {
- foreach ($entity->{$this->field_name} as $langcode => &$data) {
- if (!empty($data)) {
- foreach ($data as $delta => $item) {
- if (isset($item['value']) && $item['value'] == $this->item_id) {
- $this->langcode = $langcode;
- return $delta;
- }
- elseif (isset($item['entity']) && $item['entity'] === $this) {
- $this->langcode = $langcode;
- return $delta;
- }
- }
- }
- }
- // If we don't find the delta in the current values (cause the item
- // is being deleted, for example), we search the delta in the originalcontent.
- if (!empty($entity->original)) {
- foreach ($entity->original->{$this->field_name} as $langcode => &$data) {
- if (!empty($data)) {
- foreach ($data as $delta => $item) {
- if (isset($item['value']) && $item['value'] == $this->item_id) {
- $this->langcode = $langcode;
- return $delta;
- }
- elseif (isset($item['entity']) && $item['entity'] === $this) {
- $this->langcode = $langcode;
- return $delta;
- }
- }
- }
- }
- }
- }
- }
-
- /**
- * Determines the language code under which the item is stored.
- */
- public function langcode() {
- if ($this->delta() === NULL || empty($this->langcode)) {
- $this->langcode = field_collection_entity_language('field_collection_item', $this);
- }
-
- if (empty($this->langcode) || ($this->langcode != LANGUAGE_NONE && (!module_exists('entity_translation') || !entity_translation_enabled('field_collection_item')))) {
- $this->langcode = LANGUAGE_NONE;
- }
-
- return $this->langcode;
- }
-
- /**
- * Determines whether this field collection item revision is in use.
- *
- * Field collection items may be contained in from non-default host entity
- * revisions. If the field collection item does not appear in the default
- * host entity revision, the item is actually not used by default and so
- * marked as 'archived'.
- * If the field collection item appears in the default revision of the host
- * entity, the default revision of the field collection item is in use there
- * and the collection is not marked as archived.
- */
- public function isInUse() {
- return $this->default_revision && !$this->archived;
- }
-
- /**
- * Save the field collection item.
- *
- * By default, always save the host entity, so modules are able to react
- * upon changes to the content of the host and any 'last updated' dates of
- * entities get updated.
- *
- * For creating an item a host entity has to be specified via setHostEntity()
- * before this function is invoked. For the link between the entities to be
- * fully established, the host entity object has to be updated to include a
- * reference on this field collection item during saving. So do not skip
- * saving the host for creating items.
- *
- * @param $skip_host_save
- * (internal) If TRUE is passed, the host entity is not saved automatically
- * and therefore no link is created between the host and the item or
- * revision updates might be skipped. Use with care.
- */
- public function save($skip_host_save = FALSE) {
- // Make sure we have a host entity during creation.
- if (!empty($this->is_new) && !(isset($this->hostEntityId) || isset($this->hostEntity) || isset($this->hostEntityRevisionId))) {
- throw new Exception("Unable to create a field collection item without a given host entity.");
- }
-
- // Copy the values of translatable fields for a new field collection item.
- if (field_collection_item_is_translatable() && !empty($this->is_new) && $this->langcode() == LANGUAGE_NONE) {
- $this->copyTranslations();
- }
-
- // Only save directly if we are told to skip saving the host entity. Else,
- // we always save via the host as saving the host might trigger saving
- // field collection items anyway (e.g. if a new revision is created).
- if ($skip_host_save) {
- return entity_get_controller($this->entityType)->save($this);
- }
- else {
- $host_entity = $this->hostEntity();
- if (!$host_entity) {
- throw new Exception("Unable to save a field collection item without a valid reference to a host entity.");
- }
- // If this is creating a new revision, also do so for the host entity.
- if (!empty($this->revision) || !empty($this->is_new_revision)) {
- $host_entity->revision = TRUE;
- if (!empty($this->default_revision)) {
- entity_revision_set_default($this->hostEntityType, $host_entity);
- }
- }
- // Set the host entity reference, so the item will be saved with the host.
- // @see field_collection_field_presave()
- $delta = $this->delta();
- if (isset($delta)) {
- $host_entity->{$this->field_name}[$this->langcode()][$delta] = array('entity' => $this);
- }
- else {
- $host_entity->{$this->field_name}[$this->langcode()][] = array('entity' => $this);
- }
-
- return entity_save($this->hostEntityType, $host_entity);
- }
- }
-
- /**
- * Deletes the field collection item and the reference in the host entity.
- */
- public function delete() {
- parent::delete();
- $this->deleteHostEntityReference();
- }
-
- /**
- * Copies text to all languages the collection item has a translation for.
- *
- * @param $source_language
- * Language code to copy the text from.
- */
- public function copyTranslations($source_language = NULL) {
- // Get a handler for Entity Translation if there is one.
- $host_et_handler = NULL;
- if (module_exists('entity_translation')) {
- $host_et_handler = entity_translation_get_handler($this->hostEntityType(), $this->hostEntity());
- }
- if (is_null($host_et_handler)) {
- return;
- }
-
- $host_languages = array_keys($host_et_handler->getTranslations()->data);
- if (empty($host_languages)) {
- $host_languages = array(entity_language($this->hostEntityType(), $this->hostEntity()));
- }
- $source_language = isset($source_language) ? $source_language : $host_et_handler->getLanguage();
- $target_languages = array_diff($host_languages, array($source_language));
- $fields_instances = array_keys(field_info_instances('field_collection_item', $this->field_name));
- $fields = field_info_fields();
-
- foreach ($fields_instances as $translatable_field) {
- if ($fields[$translatable_field]['translatable'] == 1) {
- foreach ($target_languages as $langcode) {
- if (isset($this->{$translatable_field}[$source_language])) {
- //Source (translatable_field) is set, therefore continue processing.
- if(!isset($this->{$translatable_field}[$langcode])) {
- //Destination (translatable_field) is not set, therefore safe to copy the translation.
- $this->{$translatable_field}[$langcode] = $this->{$translatable_field}[$source_language];
- }
- }
- }
- if ($source_language == LANGUAGE_NONE && count($this->{$translatable_field}) > 1) {
- $this->{$translatable_field}[$source_language] = NULL;
- }
- }
- }
- }
-
- /**
- * Deletes the host entity's reference of the field collection item.
- */
- protected function deleteHostEntityReference() {
- $delta = $this->delta();
- if ($this->item_id && isset($delta)) {
- unset($this->hostEntity->{$this->field_name}[$this->langcode()][$delta]);
- // Do not save when the host entity is being deleted. See
- // field_collection_field_delete().
- if (empty($this->hostEntity->field_collection_deleting)) {
- entity_save($this->hostEntityType(), $this->hostEntity());
- }
- }
- }
-
- /**
- * Intelligently delete a field collection item revision.
- *
- * If a host entity is revisioned with its field collection items, deleting
- * a field collection item on the default revision of the host should not
- * delete the collection item from archived revisions too. Instead, we delete
- * the current default revision and archive the field collection.
- */
- public function deleteRevision($skip_host_update = FALSE) {
- if (!$this->revision_id) {
- return;
- }
-
- if (!$skip_host_update) {
- // Just remove the item from the host, which cares about deleting the
- // item (depending on whether the update creates a new revision).
- $this->deleteHostEntityReference();
- }
-
- if (!$this->isDefaultRevision()) {
- entity_revision_delete('field_collection_item', $this->revision_id);
- }
- // If deleting the default revision, take care!
- else {
- $row = db_select('field_collection_item_revision', 'r')
- ->fields('r')
- ->condition('item_id', $this->item_id)
- ->condition('revision_id', $this->revision_id, '<>')
- ->execute()
- ->fetchAssoc();
-
- if ($row) {
- // Make the other revision the default revision and archive the item.
- db_update('field_collection_item')
- ->fields(array('archived' => 1, 'revision_id' => $row['revision_id']))
- ->condition('item_id', $this->item_id)
- ->execute();
- entity_get_controller('field_collection_item')->resetCache(array($this->item_id));
- entity_revision_delete('field_collection_item', $this->revision_id);
- }
- if (!$row && !isset($this->hostEntity()->{$this->field_name}[$this->langcode()][$this->delta()])) {
- // Delete if there is no existing revision or translation to be saved.
- $this->delete();
- }
- }
- }
-
- /**
- * Export the field collection item.
- *
- * Since field collection entities are not directly exportable (i.e., do not
- * have 'exportable' set to TRUE in hook_entity_info()) and since Features
- * calls this method when exporting the field collection as a field attached
- * to another entity, we return the export in the format expected by
- * Features, rather than in the normal Entity::export() format.
- */
- public function export($prefix = '') {
- // Based on code in EntityDefaultFeaturesController::export_render().
- $export = "entity_import('" . $this->entityType() . "', '";
- $export .= addcslashes(parent::export(), '\\\'');
- $export .= "')";
- return $export;
- }
-
- /**
- * Generate an array for rendering the field collection item.
- */
- public function view($view_mode = 'full', $langcode = NULL, $page = NULL) {
- // Allow modules to change the view mode.
- $view_mode = key(entity_view_mode_prepare($this->entityType, array($this->item_id => $this), $view_mode, $langcode));
- return parent::view($view_mode, $langcode, $page);
- }
-
- /**
- * Magic method to only serialize what's necessary.
- */
- public function __sleep() {
- $vars = get_object_vars($this);
- unset($vars['entityInfo'], $vars['idKey'], $vars['nameKey'], $vars['statusKey']);
- unset($vars['fieldInfo']);
- // Also do not serialize the host entity, but only if it has already an id.
- if ($this->hostEntity && ($this->hostEntityId || $this->hostEntityRevisionId)) {
- unset($vars['hostEntity']);
- }
-
- // Also key the returned array with the variable names so the method may
- // be easily overridden and customized.
- return drupal_map_assoc(array_keys($vars));
- }
-
- /**
- * Magic method to invoke setUp() on unserialization.
- *
- * @todo: Remove this once it appears in a released entity API module version.
- */
- public function __wakeup() {
- $this->setUp();
- }
-}
diff --git a/sites/all/modules/contrib/fields/field_collection/field_collection.info b/sites/all/modules/contrib/fields/field_collection/field_collection.info
deleted file mode 100644
index 6ec462ae..00000000
--- a/sites/all/modules/contrib/fields/field_collection/field_collection.info
+++ /dev/null
@@ -1,20 +0,0 @@
-name = Field collection
-description = Provides a field collection field, to which any number of fields can be attached.
-core = 7.x
-dependencies[] = entity
-test_dependencies[] = entity_translation
-files[] = field_collection.test
-files[] = field_collection.entity.inc
-files[] = field_collection.info.inc
-files[] = includes/translation.handler.field_collection_item.inc
-files[] = views/field_collection_handler_relationship.inc
-files[] = field_collection.migrate.inc
-configure = admin/structure/field-collections
-package = Fields
-
-; Information added by Drupal.org packaging script on 2016-11-17
-version = "7.x-1.0-beta12"
-core = "7.x"
-project = "field_collection"
-datestamp = "1479402861"
-
diff --git a/sites/all/modules/contrib/fields/field_collection/field_collection.info.inc b/sites/all/modules/contrib/fields/field_collection/field_collection.info.inc
deleted file mode 100644
index 03c961a1..00000000
--- a/sites/all/modules/contrib/fields/field_collection/field_collection.info.inc
+++ /dev/null
@@ -1,30 +0,0 @@
- t('Host entity'),
- 'type' => 'entity',
- 'description' => t('The entity containing the field collection field.'),
- 'getter callback' => 'field_collection_item_get_host_entity',
- 'setter callback' => 'field_collection_item_set_host_entity',
- 'required' => TRUE,
- );
-
- return $info;
- }
-
-}
\ No newline at end of file
diff --git a/sites/all/modules/contrib/fields/field_collection/field_collection.install b/sites/all/modules/contrib/fields/field_collection/field_collection.install
deleted file mode 100644
index 7296346d..00000000
--- a/sites/all/modules/contrib/fields/field_collection/field_collection.install
+++ /dev/null
@@ -1,383 +0,0 @@
- 'Stores information about field collection items.',
- 'fields' => array(
- 'item_id' => array(
- 'type' => 'serial',
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique field collection item ID.',
- ),
- 'revision_id' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'description' => 'Default revision ID.',
- ),
- 'field_name' => array(
- 'description' => 'The name of the field on the host entity embedding this entity.',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- ),
- 'archived' => array(
- 'description' => 'Boolean indicating whether the field collection item is archived.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'primary key' => array('item_id'),
- );
- $schema['field_collection_item_revision'] = array(
- 'description' => 'Stores revision information about field collection items.',
- 'fields' => array(
- 'revision_id' => array(
- 'type' => 'serial',
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique revision ID.',
- ),
- 'item_id' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'description' => 'Field collection item ID.',
- ),
- ),
- 'primary key' => array('revision_id'),
- 'indexes' => array(
- 'item_id' => array('item_id'),
- ),
- 'foreign keys' => array(
- 'versioned_field_collection_item' => array(
- 'table' => 'field_collection_item',
- 'columns' => array('item_id' => 'item_id'),
- ),
- ),
- );
- return $schema;
-}
-
-/**
- * Implements hook_field_schema().
- */
-function field_collection_field_schema($field) {
- $columns = array(
- 'value' => array(
- 'type' => 'int',
- 'not null' => FALSE,
- 'description' => 'The field collection item id.',
- ),
- 'revision_id' => array(
- 'type' => 'int',
- 'not null' => FALSE,
- 'description' => 'The field collection item revision id.',
- ),
- );
- return array(
- 'columns' => $columns,
- 'indexes' => array(
- 'value' => array('value'),
- 'revision_id' => array('revision_id'),
- ),
- );
-}
-
-/**
- * Update the administer field collection permission machine name.
- */
-function field_collection_update_7000() {
- db_update('role_permission')
- ->fields(array('permission' => 'administer field collections'))
- ->condition('permission', 'administer field-collections')
- ->execute();
-}
-
-/**
- * Add revision support.
- */
-function field_collection_update_7001() {
-
- // Add revision_id column to field_collection_item table.
- $revision_id_spec = array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'description' => 'Default revision ID.',
- // Set default to 0 temporarily.
- 'initial' => 0,
- );
- // Field may already exist due to bug in 7.x-1.0-beta5.
- if (!db_field_exists('field_collection_item', 'revision_id')) {
- db_add_field('field_collection_item', 'revision_id', $revision_id_spec);
- }
-
- // Initialize the revision_id to be the same as the item_id.
- db_update('field_collection_item')
- ->expression('revision_id', 'item_id')
- ->execute();
-
- // Add the archived column
- $archived_spec = array(
- 'description' => 'Boolean indicating whether the field collection item is archived.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- );
- // Field may already exist due to bug in 7.x-1.0-beta5.
- if (!db_field_exists('field_collection_item', 'archived')) {
- db_add_field('field_collection_item', 'archived', $archived_spec);
- }
-
- // Create the new table. It is important to explicitly define the schema here
- // rather than use the hook_schema definition: http://drupal.org/node/150220.
- $schema['field_collection_item_revision'] = array(
- 'description' => 'Stores revision information about field collection items.',
- 'fields' => array(
- 'revision_id' => array(
- 'type' => 'serial',
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique revision ID.',
- ),
- 'item_id' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'description' => 'Field collection item ID.',
- ),
- ),
- 'primary key' => array('revision_id'),
- 'indexes' => array(
- 'item_id' => array('item_id'),
- ),
- 'foreign keys' => array(
- 'versioned_field_collection_item' => array(
- 'table' => 'field_collection_item',
- 'columns' => array('item_id' => 'item_id'),
- ),
- ),
- );
- // Table may already exist due to bug in 7.x-1.0-beta5.
- if (db_table_exists('field_collection_item_revision')) {
- db_drop_table('field_collection_item_revision');
- }
- db_create_table('field_collection_item_revision', $schema['field_collection_item_revision']);
-
- // Fill the new table with the correct data.
- $items = db_select('field_collection_item', 'fci')
- ->fields('fci')
- ->execute();
- foreach ($items as $item) {
- // Update field_collection_item_revision table.
- db_insert('field_collection_item_revision')
- ->fields(array(
- 'revision_id' => $item->item_id,
- 'item_id' => $item->item_id,
- ))
- ->execute();
- }
-
- // Update the field_collection_field_schema columns for all tables.
- // Add a revision_id column.
- $revision_id_spec['description'] = 'The field collection item revision id.';
- // Because $value_column below can be null, so must $revision_id_column.
- $revision_id_spec['not null'] = FALSE;
- foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
- $table_prefixes = array('field_data', 'field_revision');
- foreach ($table_prefixes as $table_prefix) {
-
- $table = sprintf('%s_%s', $table_prefix, $field_name);
- $value_column = sprintf('%s_value', $field_name);
- $revision_id_column = sprintf('%s_revision_id', $field_name);
-
- // Field may already exist due to bug in 7.x-1.0-beta5.
- if (!db_field_exists($table, $revision_id_column)) {
- db_add_field($table, $revision_id_column, $revision_id_spec);
- }
- else {
- db_change_field($table, $revision_id_column, $revision_id_column, $revision_id_spec);
- }
-
- // Initialize the revision_id to be the same as the item_id.
- db_update($table)
- ->expression($revision_id_column, $value_column)
- ->execute();
- }
- }
-
- // Need to get the system up-to-date so drupal_schema_fields_sql() will work.
- $schema = drupal_get_schema('field_collection_item_revision', TRUE);
-}
-
-/**
- * Remove orphaned field collection item entities.
- */
-function field_collection_update_7002() {
- // Loop over all fields and delete any orphaned field collection items.
- foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
-
- $select = db_select('field_collection_item', 'fci')
- ->fields('fci', array('item_id'))
- ->condition('field_name', $field_name)
- ->condition('archived', 0);
- $select->leftJoin('field_data_' . $field_name, 'field', "field.{$field_name}_value = fci.item_id ");
- $select->isNull('field.entity_id');
- $ids = $select->execute()->fetchCol(0);
-
- entity_delete_multiple('field_collection_item', $ids);
- drupal_set_message(t('Deleted @count orphaned field collection items.', array('@count' => count($ids))));
- }
-}
-
-/**
- * Update field_collection_field_schema columns for all tables.
- */
-function field_collection_update_7003() {
- // Revision_id column.
- $revision_id_spec = array(
- 'type' => 'int',
- 'not null' => FALSE,
- 'description' => 'The field collection item revision id.',
- 'initial' => 0,
- );
-
- // Update the field_collection_field_schema columns for all tables,
- // in case the buggy beta5 version of field_collection_update_7001()
- // completed without complaint.
- foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
- $table_prefixes = array('field_data', 'field_revision');
- foreach ($table_prefixes as $table_prefix) {
- $table = sprintf('%s_%s', $table_prefix, $field_name);
- $value_column = sprintf('%s_value', $field_name);
- $revision_id_column = sprintf('%s_revision_id', $field_name);
- db_change_field($table, $revision_id_column, $revision_id_column, $revision_id_spec);
- }
- }
-
- // Need to get the system up-to-date so drupal_schema_fields_sql() will work.
- $schema = drupal_get_schema('field_collection_item_revision', TRUE);
-}
-
-/**
- * Add index on {$field_collection_field}_revision_id column for all tables.
- */
-function field_collection_update_7004() {
- // Update the field_collection_field_schema columns for all tables.
- foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
- $table_prefixes = array('field_data', 'field_revision');
- foreach ($table_prefixes as $table_prefix) {
-
- $table = sprintf('%s_%s', $table_prefix, $field_name);
- $revision_id_column = sprintf('%s_revision_id', $field_name);
-
- // Add index on revision_id column.
- if (!db_index_exists($table, $revision_id_column)) {
- db_add_index($table, $revision_id_column, array($revision_id_column));
- }
- }
- }
-}
-
-/**
- * Force the creation of the table cache_entity_field_collection_item.
- *
- * entity_update_7003 will attempt to install entitycache tables for existing
- * modules, but it uses module_list() to get the list of available modules,
- * which, when called from a database update, may not return field_collection
- * since drupal is bootstrapped at a lower level.
- */
-function field_collection_update_7005() {
- if (module_exists('entitycache')) {
- $entity_type = 'field_collection_item';
- $table = 'cache_entity_' . $entity_type;
- if (!db_table_exists($table)) {
- $schema = drupal_get_schema_unprocessed('system', 'cache');
- $schema['description'] = 'Cache table used to store' . $entity_type . ' entity records.';
- db_create_table($table, $schema);
- }
- }
-}
-
-/**
- * Ensures revision_id indexes are present at field_config table.
- */
-function field_collection_update_7006() {
- $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE type = 'field_collection'");
- foreach ($result as $field_config) {
- $data = unserialize($field_config->data);
- // Skip this record if the revision_id index is already present.
- if (isset($data['indexes']['revision_id'])) {
- continue;
- }
- // Otherwise, add the revision_id index and update the record.
- $data['indexes']['revision_id'] = array('revision_id');
- $data = serialize($data);
- $num_updated = db_update('field_config')
- ->fields(array('data' => $data))
- ->condition('id', $field_config->id)
- ->execute();
- // If for some reason the update failed, throw an exception.
- if ($num_updated != 1) {
- $t_args['@field'] = $field_config->field_name;
- throw new DrupalUpdateException(t('An error was detected when attempting to update field configuration for field @field.', $t_args));
- }
- }
-}
-
-/**
- * Add index on {$field_collection_field}_value column for all tables.
- */
-function field_collection_update_7007() {
- foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
- if (!isset($field['indexes']['value'])) {
- // Add index on the value column and update the field.
- $field['indexes']['value'] = array('value');
- field_update_field($field);
- }
-
- $table_prefixes = array('field_data', 'field_revision');
- foreach ($table_prefixes as $table_prefix) {
- $table = "{$table_prefix}_{$field_name}";
- $value_column = "{$field_name}_value";
- if (!db_index_exists($table, $value_column)) {
- // Add index on the value column.
- db_add_index($table, $value_column, array($value_column));
- }
- }
- }
-}
-
-/**
- * Update fields in field collections already set to use Entity Translation.
- */
-function field_collection_update_7008() {
- // Include FieldCollectionItemEntity class.
- module_load_include('inc', 'field_collection', 'field_collection.entity');
-
- $results = array();
- foreach (field_info_fields() as $f_name => $field) {
- if ($field['translatable'] == 1 && isset($field['bundles']['field_collection_item'])) {
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'field_collection_item')
- ->fieldLanguageCondition($f_name, LANGUAGE_NONE);
- $query_result = $query->execute();
- if (isset($query_result['field_collection_item'])) {
- $results = $results + $query_result['field_collection_item'];
- }
- }
- }
- if (count($results)) {
- $ids = array_keys($results);
- $field_collection_items = entity_load('field_collection_item', $ids);
- foreach ($field_collection_items as $item) {
- $item->copyTranslations(LANGUAGE_NONE);
- $item->save();
- }
- }
-}
diff --git a/sites/all/modules/contrib/fields/field_collection/field_collection.migrate.inc b/sites/all/modules/contrib/fields/field_collection/field_collection.migrate.inc
deleted file mode 100644
index b20bbb39..00000000
--- a/sites/all/modules/contrib/fields/field_collection/field_collection.migrate.inc
+++ /dev/null
@@ -1,190 +0,0 @@
-dependencies = array('Article');
- *
- * $this->destination = new MigrateDestinationFieldCollection(
- * 'field_attached_data',
- * array('host_entity_type' => 'node')
- * );
- *
- * $this->addFieldMapping('host_entity_id', 'source_article_id')
- * ->sourceMigration('Article');
- * @endcode
- *
- * @see http://drupal.org/node/1900640
- */
-
-/**
- * Destination class implementing migration into field_collection.
- */
-class MigrateDestinationFieldCollection extends MigrateDestinationEntity {
- /**
- * The type of entity hosting this collection field (e.g., node).
- *
- * @var string
- */
- protected $hostEntityType;
-
- static public function getKeySchema() {
- return array(
- 'item_id' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'ID of field collection item',
- ),
- );
- }
-
- /**
- * Basic initialization.
- *
- * @param string $bundle
- * Bundle name.
- * @param array $options
- * (optional) Options applied to collections.
- */
- public function __construct($bundle, array $options = array()) {
- parent::__construct('field_collection_item', $bundle, $options);
- $this->hostEntityType = $options['host_entity_type'];
- }
-
- /**
- * Returns a list of fields available to be mapped for this collection
- * (bundle).
- *
- * @return array
- * Keys: machine names of the fields (to be passed to addFieldMapping).
- * Values: Human-friendly descriptions of the fields.
- */
- public function fields() {
- $fields = migrate_handler_invoke_all('Entity', 'fields', $this->entityType, $this->bundle);
- $fields['item_id'] = t('Field collection entity ID');
- $fields['host_entity_id'] = t('Field collection host ID');
- return $fields;
- }
-
- /**
- * Import a single field collection item.
- *
- * @param $collection
- * Collection object to build. Pre-filled with any fields mapped in the
- * migration.
- * @param $row
- * Raw source data object - passed through to prepare/complete handlers.
- *
- * @return array|false
- * Array of key fields (item_id only in this case) of the collection that
- * was saved or FALSE on failure.
- */
- public function import(stdClass $collection, stdClass $row) {
- $updating = FALSE;
- if (isset($row->migrate_map_destid1)) {
- // We're updated an existing entity - start from the previous data.
- // entity_load() returns an array, so we get the field collection entity
- // with array_shift().
- if ($entity = array_shift(entity_load('field_collection_item', array($row->migrate_map_destid1), array(), TRUE))) {
- $entity_old = clone $entity;
- $updating = TRUE;
- }
- }
-
- if (!$updating) {
- // Skip the collection if it has no host.
- if (empty($collection->host_entity_id)) {
- throw new MigrateException('Could not find host entity of the field collection to import.');
- }
- $entity = entity_create('field_collection_item', array('field_name' => $this->bundle));
- $updating = FALSE;
- $host_entity = entity_load_single($this->hostEntityType, $collection->host_entity_id);
- entity_get_controller($this->hostEntityType)->resetCache();
-
- if (isset($row->language)) {
- $entity->setHostEntity($this->hostEntityType, $host_entity, $row->language, TRUE);
- }
- else {
- $entity->setHostEntity($this->hostEntityType, $host_entity);
- }
- }
-
- unset($collection->host_entity_id);
-
- foreach ((array) $collection as $field => $value) {
- $entity->{$field} = $value;
- }
-
- $this->prepare($entity, $row);
-
- // Restore fields from original field_collection_item if updating
- if ($updating) {
- foreach ($entity as $field => $value) {
- if ('field_' != substr($field, 0, 6)) {
- continue;
- }
- elseif (property_exists($entity_old, $field) && !property_exists($collection, $field)) {
- $entity->$field = $entity_old->$field;
- }
- }
- }
-
- migrate_instrument_start('field_collection_save');
- $status = entity_save('field_collection_item', $entity);
- migrate_instrument_stop('field_collection_save');
-
- if (in_array($this->hostEntityType, array('node', 'field_collection_item')) || ($status !== FALSE)) {
- $this->complete($entity, $row);
- if ($updating) {
- $this->numUpdated++;
- }
- else {
- $this->numCreated++;
- }
- return array($entity->item_id);
- }
- else {
- return FALSE;
- }
- }
-
- /**
- * Delete a migrated collection.
- *
- * @param $key
- * Array of fields representing the key.
- */
- public function rollback(array $key) {
- $item_id = reset($key);
-
- $this->prepareRollback($item_id);
- $field_collection_item = field_collection_item_load($item_id);
- // If the collection wasn't imported then we can't roll it back, so check if
- // the loaded object is an instance of the FieldCollectionItemEntity class.
- if ($field_collection_item instanceof FieldCollectionItemEntity) {
- $field_collection_item->delete();
- }
-
- $this->completeRollback($item_id);
- return TRUE;
- }
-}
-
-/**
- * Implements migrate hook_migrate_api().
- */
-function field_collection_migrate_api() {
- $api = array(
- 'api' => 2,
- );
- return $api;
-}
diff --git a/sites/all/modules/contrib/fields/field_collection/field_collection.module b/sites/all/modules/contrib/fields/field_collection/field_collection.module
deleted file mode 100644
index 8c985992..00000000
--- a/sites/all/modules/contrib/fields/field_collection/field_collection.module
+++ /dev/null
@@ -1,1947 +0,0 @@
-' . t('About') . '';
- $output .= '
' . t('The field collection module provides a field, to which any number of fields can be attached. See the Field module help page for more information about fields.', array('@field-help' => url('admin/help/field'))) . '
';
- return $output;
- }
-}
-
-/**
- * Implements hook_form_alter().
- *
- * Checks for a value set by the embedded widget so fields are not displayed
- * with the 'all languages' hint incorrectly.
- */
-function field_collection_form_alter(&$form, &$form_state) {
- if (!empty($form['#field_collection_translation_fields'])) {
- foreach ($form['#field_collection_translation_fields'] as $address) {
- drupal_array_set_nested_value($form, array_merge($address, array('#multilingual')), TRUE);
- }
- }
-}
-
-/**
- * Implements hook_form_FORM_ID_alter() for field_ui_field_overview_form().
- *
- * Make the names of the field collection fields into links to edit the fields
- * for that field collection on the host's field edit page.
- */
-function field_collection_form_field_ui_field_overview_form_alter(&$form, &$form_state) {
- if (count($form['#fields'])) {
- foreach($form['fields'] as $fieldname => $field) {
- if (!isset($field['type']['#title'])) {
- continue;
- }
- if ($field['type']['#title'] == 'Field collection') {
- $form['fields'][$fieldname]['field_name']['#markup'] =
- l($form['fields'][$fieldname]['field_name']['#markup'], 'admin/structure/field-collections/' . str_replace('_', '-', $fieldname) . '/fields');
- }
- }
- }
-}
-
-/**
- * Implements hook_ctools_plugin_directory().
- */
-function field_collection_ctools_plugin_directory($module, $plugin) {
- if ($module == 'ctools') {
- return 'ctools/' . $plugin;
- }
-}
-
-/**
- * Implements hook_entity_info().
- */
-function field_collection_entity_info() {
- $return['field_collection_item'] = array(
- 'label' => t('Field collection item'),
- 'label callback' => 'entity_class_label',
- 'uri callback' => 'entity_class_uri',
- 'entity class' => 'FieldCollectionItemEntity',
- 'controller class' => 'EntityAPIController',
- 'base table' => 'field_collection_item',
- 'revision table' => 'field_collection_item_revision',
- 'fieldable' => TRUE,
- // For integration with Redirect module.
- // @see http://drupal.org/node/1263884
- 'redirect' => FALSE,
- 'entity keys' => array(
- 'id' => 'item_id',
- 'revision' => 'revision_id',
- 'bundle' => 'field_name',
- ),
- 'module' => 'field_collection',
- 'view modes' => array(
- 'full' => array(
- 'label' => t('Full content'),
- 'custom settings' => FALSE,
- ),
- ),
- 'access callback' => 'field_collection_item_access',
- 'deletion callback' => 'field_collection_item_delete',
- 'metadata controller class' => 'FieldCollectionItemMetadataController',
- 'translation' => array(
- 'entity_translation' => array(
- 'class' => 'EntityTranslationFieldCollectionItemHandler',
- ),
- ),
- );
-
- // Add info about the bundles. We do not use field_info_fields() but directly
- // use field_read_fields() as field_info_fields() requires built entity info
- // to work.
- foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
- $return['field_collection_item']['bundles'][$field_name] = array(
- 'label' => t('Field collection @field', array('@field' => $field_name)),
- 'admin' => array(
- 'path' => 'admin/structure/field-collections/%field_collection_field_name',
- 'real path' => 'admin/structure/field-collections/' . strtr($field_name, array('_' => '-')),
- 'bundle argument' => 3,
- 'access arguments' => array('administer field collections'),
- ),
- );
-
- $path = field_collection_field_get_path($field) . '/%field_collection_item';
- // Enable the first available path scheme as default one.
- if (!isset($return['field_collection_item']['translation']['entity_translation']['base path'])) {
- $return['field_collection_item']['translation']['entity_translation']['base path'] = $path;
- $return['field_collection_item']['translation']['entity_translation']['path wildcard'] = '%field_collection_item';
- $return['field_collection_item']['translation']['entity_translation']['default_scheme'] = $field_name;
- }
- else {
- $return['field_collection_item']['translation']['entity_translation']['path schemes'][$field_name] = array(
- 'base path' => $path,
- );
- }
- }
-
- if (module_exists('entitycache')) {
- $return['field_collection_item']['field cache'] = FALSE;
- $return['field_collection_item']['entity cache'] = TRUE;
- }
-
- return $return;
-}
-
-/**
- * Provide the original entity language.
- *
- * If a language property is defined for the current entity we synchronize the
- * field value using the entity language, otherwise we fall back to
- * LANGUAGE_NONE.
- *
- * @param $entity_type
- * @param $entity
- *
- * @return
- * A language code
- */
-function field_collection_entity_language($entity_type, $entity) {
- if (module_exists('entity_translation') && entity_translation_enabled($entity_type)) {
- $handler = entity_translation_get_handler($entity_type, $entity);
- $langcode = $handler->getLanguage();
- }
- else {
- $langcode = entity_language($entity_type, $entity);
- }
- return !empty($langcode) ? $langcode : LANGUAGE_NONE;
-}
-
-/**
- * Menu callback for loading the bundle names.
- */
-function field_collection_field_name_load($arg) {
- $field_name = strtr($arg, array('-' => '_'));
- if (($field = field_info_field($field_name)) && $field['type'] == 'field_collection') {
- return $field_name;
- }
-}
-
-/**
- * Loads a field collection item.
- *
- * @return field_collection_item
- * The field collection item entity or FALSE.
- */
-function field_collection_item_load($item_id, $reset = FALSE) {
- $result = field_collection_item_load_multiple(array($item_id), array(), $reset);
- return $result ? reset($result) : FALSE;
-}
-
-/**
- * Loads a field collection revision.
- *
- * @param $revision_id
- * The field collection revision ID.
- */
-function field_collection_item_revision_load($revision_id) {
- return entity_revision_load('field_collection_item', $revision_id);
-}
-
-/**
- * Loads field collection items.
- *
- * @return
- * An array of field collection item entities.
- */
-function field_collection_item_load_multiple($ids = array(), $conditions = array(), $reset = FALSE) {
- return entity_load('field_collection_item', $ids, $conditions, $reset);
-}
-
-/**
- * Implements hook_menu().
- */
-function field_collection_menu() {
- $items = array();
- if (module_exists('field_ui')) {
- $items['admin/structure/field-collections'] = array(
- 'title' => 'Field collections',
- 'description' => 'Manage fields on field collections.',
- 'page callback' => 'field_collections_overview',
- 'access arguments' => array('administer field collections'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'field_collection.admin.inc',
- );
- }
-
- // Add menu paths for viewing/editing/deleting field collection items.
- foreach (field_info_fields() as $field) {
- if ($field['type'] == 'field_collection') {
- $path = field_collection_field_get_path($field);
- $count = count(explode('/', $path));
-
- $items[$path . '/%field_collection_item'] = array(
- 'page callback' => 'field_collection_item_page_view',
- 'page arguments' => array($count),
- 'access callback' => 'entity_access',
- 'access arguments' => array('view', 'field_collection_item', $count),
- 'file' => 'field_collection.pages.inc',
- );
- $items[$path . '/%field_collection_item/view'] = array(
- 'title' => 'View',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => -10,
- );
- $items[$path . '/%field_collection_item/edit'] = array(
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_collection_item_form', $count),
- 'access callback' => 'entity_access',
- 'access arguments' => array('update', 'field_collection_item', $count),
- 'title' => 'Edit',
- 'type' => MENU_LOCAL_TASK,
- 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
- 'file' => 'field_collection.pages.inc',
- );
- $items[$path . '/%field_collection_item/delete'] = array(
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_collection_item_delete_confirm', $count),
- 'access callback' => 'entity_access',
- 'access arguments' => array('delete', 'field_collection_item', $count),
- 'title' => 'Delete',
- 'type' => MENU_LOCAL_TASK,
- 'context' => MENU_CONTEXT_INLINE,
- 'file' => 'field_collection.pages.inc',
- );
- // Add entity type and the entity id as additional arguments.
- $items[$path . '/add/%/%'] = array(
- 'page callback' => 'field_collection_item_add',
- 'page arguments' => array($field['field_name'], $count + 1, $count + 2),
- // The pace callback takes care of checking access itself.
- 'access callback' => TRUE,
- 'file' => 'field_collection.pages.inc',
- );
- // Add menu items for dealing with revisions.
- $items[$path . '/%field_collection_item/revisions/%field_collection_item_revision'] = array(
- 'page callback' => 'field_collection_item_page_view',
- 'page arguments' => array($count + 2),
- 'access callback' => 'entity_access',
- 'access arguments' => array('view', 'field_collection_item', $count + 2),
- 'file' => 'field_collection.pages.inc',
- );
- }
- }
-
- return $items;
-}
-
-/**
- * Implements hook_menu_alter() to fix the field collections admin UI tabs.
- */
-function field_collection_menu_alter(&$items) {
- if (module_exists('field_ui') && isset($items['admin/structure/field-collections/%field_collection_field_name/fields'])) {
- // Make the fields task the default local task.
- $items['admin/structure/field-collections/%field_collection_field_name'] = $items['admin/structure/field-collections/%field_collection_field_name/fields'];
- $item = &$items['admin/structure/field-collections/%field_collection_field_name'];
- $item['type'] = MENU_NORMAL_ITEM;
- $item['title'] = 'Manage fields';
- $item['title callback'] = 'field_collection_admin_page_title';
- $item['title arguments'] = array(3);
-
- $items['admin/structure/field-collections/%field_collection_field_name/fields'] = array(
- 'title' => 'Manage fields',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => 1,
- );
- }
-}
-
-/**
- * Menu title callback.
- */
-function field_collection_admin_page_title($field_name) {
- return t('Field collection @field_name', array('@field_name' => $field_name));
-}
-
-/**
- * Implements hook_admin_paths().
- */
-function field_collection_admin_paths() {
- if (variable_get('node_admin_theme')) {
- return array(
- 'field-collection/*/*/edit' => TRUE,
- 'field-collection/*/*/delete' => TRUE,
- 'field-collection/*/add/*/*' => TRUE,
- );
- }
-}
-
-/**
- * Implements hook_permission().
- */
-function field_collection_permission() {
- return array(
- 'administer field collections' => array(
- 'title' => t('Administer field collections'),
- 'description' => t('Create and delete fields on field collections.'),
- ),
- );
-}
-
-/**
- * Determines whether the given user has access to a field collection.
- *
- * @param $op
- * The operation being performed. One of 'view', 'update', 'create', 'delete'.
- * @param $item
- * Optionally a field collection item. If nothing is given, access for all
- * items is determined.
- * @param $account
- * The user to check for. Leave it to NULL to check for the global user.
- * @return boolean
- * Whether access is allowed or not.
- */
-function field_collection_item_access($op, FieldCollectionItemEntity $item = NULL, $account = NULL) {
- // We do not support editing field collection revisions that are not used at
- // the hosts default revision as saving the host might result in a new default
- // revision.
- if (isset($item) && !$item->isInUse() && $op != 'view') {
- return FALSE;
- }
- if (user_access('administer field collections', $account)) {
- return TRUE;
- }
- if (!isset($item)) {
- return FALSE;
- }
- $op = $op == 'view' ? 'view' : 'edit';
- // Access is determined by the entity and field containing the reference.
- $field = field_info_field($item->field_name);
- $entity_access = entity_access($op == 'view' ? 'view' : 'update', $item->hostEntityType(), $item->hostEntity(), $account);
- return $entity_access && field_access($op, $field, $item->hostEntityType(), $item->hostEntity(), $account);
-}
-
-/**
- * Deletion callback
- */
-function field_collection_item_delete($id) {
- $fci = field_collection_item_load($id);
- if (!empty($fci)) {
- $fci->delete();
- }
-}
-
-/**
- * Implements hook_theme().
- */
-function field_collection_theme() {
- return array(
- 'field_collection_item' => array(
- 'render element' => 'elements',
- 'template' => 'field-collection-item',
- ),
- 'field_collection_view' => array(
- 'render element' => 'element',
- ),
- );
-}
-
-/**
- * Implements hook_field_info().
- */
-function field_collection_field_info() {
- return array(
- 'field_collection' => array(
- 'label' => t('Field collection'),
- 'description' => t('This field stores references to embedded entities, which itself may contain any number of fields.'),
- 'instance_settings' => array(),
- 'default_widget' => 'field_collection_hidden',
- 'default_formatter' => 'field_collection_view',
- // As of now there is no UI for setting the path.
- 'settings' => array(
- 'path' => '',
- 'hide_blank_items' => TRUE,
- 'hide_initial_item' => FALSE,
- ),
- // Add entity property info.
- 'property_type' => 'field_collection_item',
- 'property_callbacks' => array('field_collection_entity_metadata_property_callback'),
- ),
- );
-}
-
-/**
- * Implements hook_field_instance_settings_form().
- */
-function field_collection_field_instance_settings_form($field, $instance) {
-
- $element['fieldset'] = array(
- '#type' => 'fieldset',
- '#title' => t('Default value'),
- '#collapsible' => FALSE,
- // As field_ui_default_value_widget() does, we change the #parents so that
- // the value below is writing to $instance in the right location.
- '#parents' => array('instance'),
- );
- // Be sure to set the default value to NULL, e.g. to repair old fields
- // that still have one.
- $element['fieldset']['default_value'] = array(
- '#type' => 'value',
- '#value' => NULL,
- );
- $element['fieldset']['content'] = array(
- '#pre' => '
',
- '#markup' => t('To specify a default value, configure it via the regular default value setting of each field that is part of the field collection. To do so, go to the Manage fields screen of the field collection.', array('!url' => url('admin/structure/field-collections/' . strtr($field['field_name'], array('_' => '-')) . '/fields'))),
- '#suffix' => '
',
- );
- return $element;
-}
-
-/**
- * Returns the base path to use for field collection items.
- */
-function field_collection_field_get_path($field) {
- if (empty($field['settings']['path'])) {
- return 'field-collection/' . strtr($field['field_name'], array('_' => '-'));
- }
- return $field['settings']['path'];
-}
-
-/**
- * Implements hook_field_settings_form().
- */
-function field_collection_field_settings_form($field, $instance) {
- $form['hide_blank_items'] = array(
- '#type' => 'checkbox',
- '#title' => t('Hide blank items'),
- '#default_value' => $field['settings']['hide_blank_items'],
- '#description' => t('Ordinarily a new blank item will be added to unlimited cardinality fields whenever they appear in a form. Checking this will prevent the blank item from appearing if the field already contains data.'),
- '#weight' => 10,
- '#states' => array(
- // Show the setting if the cardinality is -1.
- 'visible' => array(
- ':input[name="field[cardinality]"]' => array('value' => '-1'),
- ),
- ),
- );
- $form['hide_initial_item'] = array(
- '#type' => 'checkbox',
- '#title' => t('Hide initial item'),
- '#default_value' => $field['settings']['hide_initial_item'],
- '#description' => t('Prevent the default blank item from appearing even if the field has no data yet. If checked, the user must explicitly add the field collection.'),
- '#weight' => 11,
- '#states' => array(
- // Show the setting if the cardinality is -1 and hide_blank_items is checked.
- 'visible' => array(
- ':input[name="field[cardinality]"]' => array('value' => '-1'),
- ':input[name="field[settings][hide_blank_items]"]' => array('checked' => TRUE),
- ),
- ),
- );
- return $form;
-}
-
-/**
- * Implements hook_field_insert().
- */
-function field_collection_field_insert($host_entity_type, $host_entity, $field, $instance, $langcode, &$items) {
- foreach ($items as &$item) {
- if ($entity = field_collection_field_get_entity($item)) {
- if (!empty($host_entity->is_new) && empty($entity->is_new)) {
- // If the host entity is new but we have a field_collection that is not
- // new, it means that its host is being cloned. Thus we need to clone
- // the field collection entity as well.
- $new_entity = clone $entity;
- $new_entity->item_id = NULL;
- $new_entity->revision_id = NULL;
- $new_entity->is_new = TRUE;
- $entity = $new_entity;
- }
- if (!empty($entity->is_new)) {
- $entity->setHostEntity($host_entity_type, $host_entity, field_collection_entity_language($host_entity_type, $host_entity), FALSE);
- }
- $entity->save(TRUE);
- $item = array(
- 'value' => $entity->item_id,
- 'revision_id' => $entity->revision_id,
- );
- }
- }
-}
-
-/**
- * Implements hook_field_update().
- *
- * Care about removed field collection items.
- *
- * Support saving field collection items in @code $item['entity'] @endcode. This
- * may be used to seamlessly create field collection items during host-entity
- * creation or to save changes to the host entity and its collections at once.
- */
-function field_collection_field_update($host_entity_type, $host_entity, $field, $instance, $langcode, &$items) {
- // When entity language is changed field values are moved to the new language
- // and old values are marked as removed. We need to avoid processing them in
- // this case.
- $entity_langcode = field_collection_entity_language($host_entity_type, $host_entity);
- $original = isset($host_entity->original) ? $host_entity->original : $host_entity;
- $original_langcode = field_collection_entity_language($host_entity_type, $original);
- $langcode = $langcode == $original_langcode ? $entity_langcode : $langcode;
-
- $top_host = $host_entity;
- while (method_exists($top_host, 'hostEntity')) {
- $top_host = $top_host->hostEntity();
- }
-
- // Prevent workbench moderation from deleting field collections or paragraphs
- // on node_save() during workbench_moderation_store(), when
- // $host_entity->revision == 0.
- if (!empty($top_host->workbench_moderation['updating_live_revision'])) {
- return;
- }
-
- // Load items from the original entity.
- $items_original = !empty($original->{$field['field_name']}[$langcode]) ? $original->{$field['field_name']}[$langcode] : array();
- $original_by_id = array_flip(field_collection_field_item_to_ids($items_original));
-
- foreach ($items as $delta => &$item) {
- // In case the entity has been changed / created, save it and set the id.
- // If the host entity creates a new revision, save new item-revisions as
- // well.
- if (isset($item['entity']) || !empty($host_entity->revision)) {
- if ($entity = field_collection_field_get_entity($item)) {
- // If the host entity is saved as new revision, do the same for the item.
- if (!empty($host_entity->revision) || !empty($host_entity->is_new_revision)) {
- $entity->revision = TRUE;
- // Without this cache clear entity_revision_is_default will
- // incorrectly return false here when creating a new published revision
- if (!isset($cleared_host_entity_cache)) {
- list($entity_id) = entity_extract_ids($host_entity_type, $host_entity);
- entity_get_controller($host_entity_type)->resetCache(array($entity_id));
- $cleared_host_entity_cache = true;
- }
- $is_default = entity_revision_is_default($host_entity_type, $host_entity);
- // If an entity type does not support saving non-default entities,
- // assume it will be saved as default.
- if (!isset($is_default) || $is_default) {
- $entity->default_revision = TRUE;
- $entity->archived = FALSE;
- }
- else {
- $entity->default_revision = FALSE;
- }
- }
-
- if (!empty($entity->is_new)) {
- $entity->setHostEntity($host_entity_type, $host_entity, $langcode, FALSE);
- }
- else {
- $entity->updateHostEntity($host_entity, $host_entity_type);
- }
-
- $entity->save(TRUE);
-
- $item = array(
- 'value' => $entity->item_id,
- 'revision_id' => $entity->revision_id,
- );
- }
- }
-
- unset($original_by_id[$item['value']]);
- }
-
- // If there are removed items, care about deleting the item entities.
- if ($original_by_id) {
- $ids = array_flip($original_by_id);
-
- // If we are creating a new revision, the old-items should be kept but get
- // marked as archived now.
- if (!empty($host_entity->revision)) {
- db_update('field_collection_item')
- ->fields(array('archived' => 1))
- ->condition('item_id', $ids, 'IN')
- ->execute();
- }
- else {
- // Load items from the original entity from all languages checking which
- // are the unused items.
- $current_items = array();
- $languages = language_list();
- foreach ($languages as $langcode_value) {
- $current_items += !empty($host_entity->{$field['field_name']}[$langcode_value->language]) ? $host_entity->{$field['field_name']}[$langcode_value->language] : array();
- $current_by_id = field_collection_field_item_to_ids($current_items);
- }
- $items_to_remove = array_diff($ids, $current_by_id);
- // Delete unused field collection items now.
- foreach (field_collection_item_load_multiple($items_to_remove) as $un_item) {
- $un_item->updateHostEntity($host_entity);
- $un_item->deleteRevision(TRUE);
- }
- }
- }
-}
-
-/**
- * Implements hook_field_delete().
- */
-function field_collection_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
- // Also delete all embedded entities.
- if ($ids = field_collection_field_item_to_ids($items)) {
- // We filter out entities that are still being referenced by other
- // host-entities. This should never be the case, but it might happened e.g.
- // when modules cloned a node without knowing about field-collection.
- $entity_info = entity_get_info($entity_type);
- $entity_id_name = $entity_info['entity keys']['id'];
- $field_column = key($field['columns']);
-
- foreach ($ids as $id_key => $id) {
- $query = new EntityFieldQuery();
- $entities = $query
- ->fieldCondition($field['field_name'], $field_column, $id)
- ->execute();
- unset($entities[$entity_type][$entity->$entity_id_name]);
-
- if (!empty($entities[$entity_type])) {
- // Filter this $id out.
- unset($ids[$id_key]);
- }
-
- // Set a flag to remember that the host entity is being deleted. See
- // FieldCollectionItemEntity::deleteHostEntityReference().
- // Doing this on $entity is not sufficient because the cache for $entity
- // may have been reset since it was loaded. That would cause
- // hostEntity() to load it from the database later without the flag.
- $field_collection_item = field_collection_item_load($id);
- if ($field_collection_item) {
- $hostEntity = $field_collection_item->hostEntity();
- if (!empty($hostEntity)) {
- $hostEntity->field_collection_deleting = TRUE;
- }
- }
- }
-
- entity_delete_multiple('field_collection_item', $ids);
- }
-}
-
-/**
- * Implements hook_field_delete_revision().
- */
-function field_collection_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) {
- foreach ($items as $item) {
- if (!empty($item['revision_id'])) {
- if ($entity = field_collection_item_revision_load($item['revision_id'])) {
- $entity->deleteRevision(TRUE);
- }
- }
- }
-}
-
-/**
- * Get an array of field collection item IDs stored in the given field items.
- */
-function field_collection_field_item_to_ids($items) {
- $ids = array();
- foreach ($items as $item) {
- if (!empty($item['value'])) {
- $ids[] = $item['value'];
- }
- }
- return $ids;
-}
-
-/**
- * Implements hook_field_is_empty().
- */
-function field_collection_field_is_empty($item, $field) {
- if (!empty($item['value'])) {
- return FALSE;
- }
- elseif (isset($item['entity'])) {
- return field_collection_item_is_empty($item['entity']);
- }
- return TRUE;
-}
-
-/**
- * Determines whether a field collection item entity is empty based on the collection-fields.
- */
-function field_collection_item_is_empty(FieldCollectionItemEntity $item) {
- $instances = field_info_instances('field_collection_item', $item->field_name);
- $is_empty = TRUE;
-
- // Check whether all fields are booleans.
- $all_boolean = $instances && !(bool) array_filter($instances, '_field_collection_field_is_not_boolean');
-
- foreach ($instances as $instance) {
- $field_name = $instance['field_name'];
- $field = field_info_field($field_name);
-
- // Boolean fields as those are always considered non-empty, thus their
- // information is not useful and can be skipped by default.
- if (!$all_boolean && $field['type'] == 'list_boolean') {
- continue;
- }
-
- // Determine the list of languages to iterate on.
- $languages = field_available_languages('field_collection_item', $field);
-
- foreach ($languages as $langcode) {
- if (!empty($item->{$field_name}[$langcode])) {
- // If at least one collection-field is not empty; the
- // field collection item is not empty.
- foreach ($item->{$field_name}[$langcode] as $field_item) {
- if (!module_invoke($field['module'], 'field_is_empty', $field_item, $field)) {
- $is_empty = FALSE;
- }
- }
- }
- }
- }
-
- // Allow other modules a chance to alter the value before returning.
- drupal_alter('field_collection_is_empty', $is_empty, $item);
- return $is_empty;
-}
-
-/**
- * Callback used by array_filter in field_collection_is_empty.
- */
-function _field_collection_field_is_not_boolean($instance) {
- $field = field_info_field($instance['field_name']);
- return $field['type'] != 'list_boolean';
-}
-
-/**
- * Implements hook_field_formatter_info().
- */
-function field_collection_field_formatter_info() {
- return array(
- 'field_collection_list' => array(
- 'label' => t('Links to field collection items'),
- 'field types' => array('field_collection'),
- 'settings' => array(
- 'edit' => t('Edit'),
- 'translate' => t('Translate'),
- 'delete' => t('Delete'),
- 'add' => t('Add'),
- 'description' => TRUE,
- ),
- ),
- 'field_collection_view' => array(
- 'label' => t('Field collection items'),
- 'field types' => array('field_collection'),
- 'settings' => array(
- 'edit' => t('Edit'),
- 'delete' => t('Delete'),
- 'add' => t('Add'),
- 'description' => TRUE,
- 'view_mode' => 'full',
- ),
- ),
- 'field_collection_fields' => array(
- 'label' => t('Fields only'),
- 'field types' => array('field_collection'),
- 'settings' => array(
- 'view_mode' => 'full',
- ),
- ),
- );
-}
-
-/**
- * Implements hook_field_formatter_settings_form().
- */
-function field_collection_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
- $display = $instance['display'][$view_mode];
- $settings = $display['settings'];
- $elements = array();
-
- if ($display['type'] != 'field_collection_fields') {
- $elements['add'] = array(
- '#type' => 'textfield',
- '#title' => t('Add link title'),
- '#default_value' => $settings['add'],
- '#description' => t('Leave the title empty, to hide the link.'),
- );
- $elements['edit'] = array(
- '#type' => 'textfield',
- '#title' => t('Edit link title'),
- '#default_value' => $settings['edit'],
- '#description' => t('Leave the title empty, to hide the link.'),
- );
- $elements['translate'] = array(
- '#type' => 'textfield',
- '#title' => t('Translate link title'),
- '#default_value' => $settings['translate'],
- '#description' => t('Leave the title empty, to hide the link.'),
- '#access' => field_collection_item_is_translatable(),
- );
- $elements['delete'] = array(
- '#type' => 'textfield',
- '#title' => t('Delete link title'),
- '#default_value' => $settings['delete'],
- '#description' => t('Leave the title empty, to hide the link.'),
- );
- $elements['description'] = array(
- '#type' => 'checkbox',
- '#title' => t('Show the field description beside the add link.'),
- '#default_value' => $settings['description'],
- '#description' => t('If enabled and the add link is shown, the field description is shown in front of the add link.'),
- );
- }
-
- // Add a select form element for view_mode if viewing the rendered field_collection.
- if ($display['type'] !== 'field_collection_list') {
-
- $entity_type = entity_get_info('field_collection_item');
- $options = array();
- foreach ($entity_type['view modes'] as $mode => $info) {
- $options[$mode] = $info['label'];
- }
-
- $elements['view_mode'] = array(
- '#type' => 'select',
- '#title' => t('View mode'),
- '#options' => $options,
- '#default_value' => $settings['view_mode'],
- '#description' => t('Select the view mode'),
- );
- }
-
- return $elements;
-}
-
-/**
- * Implements hook_field_formatter_settings_summary().
- */
-function field_collection_field_formatter_settings_summary($field, $instance, $view_mode) {
- $display = $instance['display'][$view_mode];
- $settings = $display['settings'];
- $output = array();
-
- if ($display['type'] !== 'field_collection_fields') {
- $links = field_collection_get_operations($settings, TRUE);
- if ($links) {
- $output[] = t('Links: @links', array('@links' => check_plain(implode(', ', $links))));
- }
- else {
- $output[] = t('Links: none');
- }
- }
-
- if ($display['type'] !== 'field_collection_list') {
- $entity_type = entity_get_info('field_collection_item');
- if (!empty($entity_type['view modes'][$settings['view_mode']]['label'])) {
- $output[] = t('View mode: @mode', array('@mode' => $entity_type['view modes'][$settings['view_mode']]['label']));
- }
- }
-
- return implode(' ', $output);
-}
-
-/**
- * Implements hook_field_formatter_view().
- */
-function field_collection_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
- $element = array();
- $settings = $display['settings'];
-
- switch ($display['type']) {
- case 'field_collection_list':
-
- foreach ($items as $delta => $item) {
- if ($field_collection = field_collection_field_get_entity($item)) {
- $output = l($field_collection->label(), $field_collection->path());
- $links = array();
- foreach (field_collection_get_operations($settings) as $op => $label) {
- if ($settings[$op] && entity_access($op == 'edit' ? 'update' : $op, 'field_collection_item', $field_collection)) {
- $title = entity_i18n_string("field:{$field['field_name']}:{$instance['bundle']}:setting_$op", $settings[$op]);
- $links[] = l($title, $field_collection->path() . '/' . $op, array('query' => drupal_get_destination()));
- }
- }
- if ($links) {
- $output .= ' (' . implode('|', $links) . ')';
- }
- $element[$delta] = array('#markup' => $output);
- }
- }
- field_collection_field_formatter_links($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display);
- break;
-
- case 'field_collection_view':
-
- $view_mode = !empty($display['settings']['view_mode']) ? $display['settings']['view_mode'] : 'full';
- foreach ($items as $delta => $item) {
- if ($field_collection = field_collection_field_get_entity($item)) {
- $element[$delta]['entity'] = $field_collection->view($view_mode);
- $element[$delta]['#theme_wrappers'] = array('field_collection_view');
- $element[$delta]['#attributes']['class'][] = 'field-collection-view';
- $element[$delta]['#attributes']['class'][] = 'clearfix';
- $element[$delta]['#attributes']['class'][] = drupal_clean_css_identifier('view-mode-' . $view_mode);
-
- $links = array(
- '#theme' => 'links__field_collection_view',
- );
- $links['#attributes']['class'][] = 'field-collection-view-links';
- foreach (field_collection_get_operations($settings) as $op => $label) {
- if ($settings[$op] && entity_access($op == 'edit' ? 'update' : $op, 'field_collection_item', $field_collection)) {
- $links['#links'][$op] = array(
- 'title' => entity_i18n_string("field:{$field['field_name']}:{$instance['bundle']}:setting_$op", $settings[$op]),
- 'href' => $field_collection->path() . '/' . $op,
- 'query' => drupal_get_destination(),
- );
- }
- }
- $element[$delta]['links'] = $links;
- }
- }
- field_collection_field_formatter_links($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display);
- if (!empty($items) || !empty($element['#suffix'])) {
- $element['#attached']['css'][] = drupal_get_path('module', 'field_collection') . '/field_collection.theme.css';
- }
- break;
-
- case 'field_collection_fields':
-
- $view_mode = !empty($display['settings']['view_mode']) ? $display['settings']['view_mode'] : 'full';
- foreach ($items as $delta => $item) {
- if ($field_collection = field_collection_field_get_entity($item)) {
- $element[$delta]['entity'] = $field_collection->view($view_mode);
- }
- }
- break;
- }
-
- return $element;
-}
-
-/**
- * Returns an array of enabled operations.
- */
-function field_collection_get_operations($settings, $add = FALSE) {
- $operations = array();
-
- if ($add) {
- $operations[] = 'add';
- }
- $operations[] = 'edit';
- if (field_collection_item_is_translatable()) {
- $operations[] = 'translate';
- }
- $operations[] = 'delete';
-
- global $field_collection_operation_keys;
- $field_collection_operation_keys = array_flip($operations);
- $operations = array_filter(array_intersect_key($settings, $field_collection_operation_keys));
- asort($operations);
-
- return $operations;
-}
-
-/**
- * Helper function to add links to a field collection field.
- */
-function field_collection_field_formatter_links(&$element, $entity_type, $entity, $field, $instance, $langcode, $items, $display) {
- $settings = $display['settings'];
- $allow_create_item = FALSE;
-
- if ($settings['add'] && ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || count($items) < $field['cardinality'])) {
- // Check whether the current is allowed to create a new item.
- $field_collection_item = entity_create('field_collection_item', array('field_name' => $field['field_name']));
- $field_collection_item->setHostEntity($entity_type, $entity, $langcode, FALSE);
-
- if (entity_access('create', 'field_collection_item', $field_collection_item)) {
- $allow_create_item = TRUE;
- $path = field_collection_field_get_path($field);
- list($id) = entity_extract_ids($entity_type, $entity);
- $element['#suffix'] = '';
- if (!empty($settings['description'])) {
- $element['#suffix'] .= '
';
- }
- }
- // If there is no add link, add a special class to the last item.
- if (!empty($items) || $allow_create_item) {
- if (empty($element['#suffix'])) {
- $index = count(element_children($element)) - 1;
- $element[$index]['#attributes']['class'][] = 'field-collection-view-final';
- }
-
- $element += array('#prefix' => '', '#suffix' => '');
- $element['#prefix'] .= '