security update core+modules
This commit is contained in:
@@ -74,7 +74,8 @@ function rules_action_data_calc($input1, $op, $input2, $settings, $state, $eleme
|
||||
}
|
||||
if (isset($result)) {
|
||||
// Ensure results are valid integer values if necessary.
|
||||
$var_info = rules_array_key($element->providesVariables());
|
||||
$variables = $element->providesVariables();
|
||||
$var_info = reset($variables);
|
||||
if ($var_info['type'] == 'integer') {
|
||||
$result = (int) $result;
|
||||
}
|
||||
|
@@ -141,14 +141,14 @@ function rules_action_entity_delete($wrapper, $settings, $state, $element) {
|
||||
* Condition: Entity is new.
|
||||
*/
|
||||
function rules_condition_entity_is_new($wrapper, $settings, $state, $element) {
|
||||
return !$wrapper->getIdentifier() || !empty($entity->is_new);
|
||||
return !$wrapper->getIdentifier() || !empty($wrapper->value()->is_new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition: Entity has field.
|
||||
*/
|
||||
function rules_condition_entity_has_field($wrapper, $field_name, $settings, $state) {
|
||||
return isset($wrapper->$field_name) || isset($entity->$field_name);
|
||||
return isset($wrapper->$field_name) || isset($wrapper->value()->$field_name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,3 +157,18 @@ function rules_condition_entity_has_field($wrapper, $field_name, $settings, $sta
|
||||
function rules_condition_entity_is_of_type($wrapper, $type) {
|
||||
return $wrapper->type() == $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition: Entity is of type and bundle.
|
||||
*/
|
||||
function rules_condition_entity_is_of_bundle($wrapper, $type, $bundles) {
|
||||
return $wrapper->type() == $type && in_array($wrapper->getBundle(), $bundles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition: User has access to field.
|
||||
*/
|
||||
function rules_condition_entity_field_access(EntityDrupalWrapper $wrapper, $field_name, $op, $account = NULL) {
|
||||
$field = field_info_field($field_name);
|
||||
return !empty($field) && field_access($op, $field, $wrapper->type(), $wrapper->value(), $account = NULL);
|
||||
}
|
||||
|
@@ -268,6 +268,23 @@ function rules_entity_type_options($key = NULL) {
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options list callback for getting a list of possible entity bundles.
|
||||
*
|
||||
* @param $element
|
||||
* The element to return options for.
|
||||
*/
|
||||
function rules_entity_bundle_options(RulesAbstractPlugin $element) {
|
||||
$bundles = array();
|
||||
if (isset($element->settings['type'])) {
|
||||
$entity_info = entity_get_info($element->settings['type']);
|
||||
foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
|
||||
$bundles[$bundle_name] = $bundle_info['label'];
|
||||
}
|
||||
}
|
||||
return $bundles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity actions access callback.
|
||||
*
|
||||
@@ -348,6 +365,69 @@ function rules_entity_condition_info() {
|
||||
'group' => t('Entities'),
|
||||
'base' => 'rules_condition_entity_is_of_type',
|
||||
),
|
||||
'entity_is_of_bundle' => array(
|
||||
'label' => t('Entity is of bundle'),
|
||||
'parameter' => array(
|
||||
'entity' => array(
|
||||
'type' => 'entity',
|
||||
'label' => t('Entity'),
|
||||
'description' => t('Specifies the entity for which to evaluate the condition.'),
|
||||
),
|
||||
'type' => array(
|
||||
'type' => 'token',
|
||||
'label' => t('Entity type'),
|
||||
'description' => t('The type of the checked entity.'),
|
||||
'options list' => 'rules_entity_action_type_options',
|
||||
'restriction' => 'input',
|
||||
),
|
||||
'bundle' => array(
|
||||
'type' => 'list<text>',
|
||||
'label' => t('Entity bundle'),
|
||||
'description' => t('The condition is met if the entity is of one of the selected bundles.'),
|
||||
'options list' => 'rules_entity_bundle_options',
|
||||
'restriction' => 'input',
|
||||
),
|
||||
),
|
||||
'group' => t('Entities'),
|
||||
'base' => 'rules_condition_entity_is_of_bundle',
|
||||
),
|
||||
'entity_field_access' => array(
|
||||
'label' => t('User has field access'),
|
||||
'parameter' => array(
|
||||
'entity' => array(
|
||||
'type' => 'entity',
|
||||
'label' => t('Entity'),
|
||||
'description' => t('Specifies the entity for which to evaluate the condition.'),
|
||||
'restriction' => 'selector',
|
||||
'wrapped' => TRUE,
|
||||
),
|
||||
'field' => array(
|
||||
'type' => 'token',
|
||||
'label' => t('Field name'),
|
||||
'description' => t('The name of the field to check for.'),
|
||||
'options list' => 'rules_condition_entity_has_field_options',
|
||||
'restriction' => 'input',
|
||||
),
|
||||
'op' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('Access operation'),
|
||||
'options list' => 'rules_condition_entity_field_access_op_options',
|
||||
'restriction' => 'input',
|
||||
'optional' => TRUE,
|
||||
'default value' => 'view',
|
||||
),
|
||||
'account' => array(
|
||||
'type' => 'user',
|
||||
'label' => t('User account'),
|
||||
'description' => t('Specifies the user account for which to check access. If left empty, the currently logged in user will be used.'),
|
||||
'restriction' => 'selector',
|
||||
'optional' => TRUE,
|
||||
'default value' => NULL,
|
||||
),
|
||||
),
|
||||
'group' => t('Entities'),
|
||||
'base' => 'rules_condition_entity_field_access',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -369,6 +449,16 @@ function rules_condition_entity_has_field_options(RulesAbstractPlugin $element)
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns options for choosing a field_access() operation.
|
||||
*/
|
||||
function rules_condition_entity_field_access_op_options(RulesAbstractPlugin $element) {
|
||||
return array(
|
||||
'view' => t('View'),
|
||||
'edit' => t('Edit'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the entity has the field, if there is metadata for the field.
|
||||
*/
|
||||
@@ -396,6 +486,81 @@ function rules_condition_entity_is_of_type_assertions($element) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the selected entity type and bundle.
|
||||
*/
|
||||
function rules_condition_entity_is_of_bundle_assertions($element) {
|
||||
if ($bundle = $element->settings['bundle']) {
|
||||
$assertions = array();
|
||||
$assertions['entity']['type'] = $element->settings['type'];
|
||||
$assertions['entity']['bundle'] = $bundle;
|
||||
return $assertions;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process callback for the condition entity_is_of_bundle.
|
||||
*/
|
||||
function rules_condition_entity_is_of_bundle_process(RulesAbstractPlugin $element) {
|
||||
// If we know the entity type, auto-populate it.
|
||||
if (($info = $element->getArgumentInfo('entity')) && $info['type'] != 'entity') {
|
||||
$element->settings['type'] = $info['type'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form alter callback for the condition entity_is_of_bundle.
|
||||
*
|
||||
* Use multiple steps to configure the condition as the needed bundle field list
|
||||
* depends on the selected entity type.
|
||||
*/
|
||||
function rules_condition_entity_is_of_bundle_form_alter(&$form, &$form_state, $options, RulesAbstractPlugin $element) {
|
||||
if (empty($element->settings['entity:select'])) {
|
||||
$step = 1;
|
||||
}
|
||||
elseif (empty($element->settings['type'])) {
|
||||
$step = 2;
|
||||
}
|
||||
else {
|
||||
$step = 3;
|
||||
}
|
||||
|
||||
$form['reload'] = array(
|
||||
'#weight' => $form['submit']['#weight'] + 1,
|
||||
'#type' => 'submit',
|
||||
'#name' => 'reload',
|
||||
'#value' => $step != 3 ? t('Continue') : t('Reload form'),
|
||||
'#limit_validation_errors' => array(array('parameter', 'entity'), array('parameter', 'type')),
|
||||
'#submit' => array('rules_form_submit_rebuild'),
|
||||
'#ajax' => rules_ui_form_default_ajax('fade'),
|
||||
'#attributes' => array('class' => array('rules-hide-js')),
|
||||
);
|
||||
// Use ajax and trigger as the reload button.
|
||||
$form['parameter']['type']['settings']['type']['#ajax'] = $form['reload']['#ajax'] + array(
|
||||
'event' => 'change',
|
||||
'trigger_as' => array('name' => 'reload'),
|
||||
);
|
||||
|
||||
switch ($step) {
|
||||
case 1:
|
||||
$form['reload']['#limit_validation_errors'] = array(array('parameter', 'entity'));
|
||||
unset($form['parameter']['type']);
|
||||
unset($form['reload']['#attributes']['class']);
|
||||
// NO break;
|
||||
case 2:
|
||||
$form['negate']['#access'] = FALSE;
|
||||
unset($form['parameter']['bundle']);
|
||||
unset($form['submit']);
|
||||
break;
|
||||
case 3:
|
||||
if (($info = $element->getArgumentInfo('entity')) && $info['type'] != 'entity') {
|
||||
// Hide the entity type parameter if not needed.
|
||||
unset($form['parameter']['type']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user