/** * Returns the configuration form for the operation. * Only called if the operation is declared as configurable. * * @param $form * The views form. * @param $form_state * An array containing the current state of the form. * @param $context * An array of related data provided by the caller ("selection", for example). */ public function form($form, &$form_state, array $context) { $entity_key = $this->operationInfo['parameters']['entity_key']; // List types need to match the original, so passing list<node> instead of // list<entity> won't work. However, passing 'node' instead of 'entity' // will work, and is needed in order to get the right tokens. $list_type = 'list<' . $this->operationInfo['type'] . '>'; $entity_type = $this->aggregate() ? $list_type : $this->entityType; $info = entity_get_info($this->entityType); // The component is wrapped in an action set so that the configuration form // has access to the entity's tokens. $set = rules_action_set(array($entity_key => array('type' => $entity_type, 'label' => $info['label']))); $action = rules_action('component_' . $this->operationInfo['key'], array($entity_key . ':select' => $entity_key)); $set->action($action); $action->form($form, $form_state); // Remove the form element for the "entity" param. It will be passed in manually. unset($form['parameter'][$entity_key]); return $form; }
/** * Returns the configuration form for the operation. * Only called if the operation is declared as configurable. * * @param $form * The views form. * @param $form_state * An array containing the current state of the form. * @param $context * An array of related data provided by the caller. */ public function form($form, &$form_state, array $context) { $entity_key = $this->operationInfo['parameters']['entity_key']; // List types need to match the original, so passing list<node> instead of // list<entity> won't work. However, passing 'node' instead of 'entity' // will work, and is needed in order to get the right tokens. $list_type = 'list<' . $this->operationInfo['type'] . '>'; $entity_type = $this->aggregate() ? $list_type : $this->entityType; $info = entity_get_info($this->entityType); // The component action is wrapped in an action set using the entity, so // that the action configuration form can make use of the entity e.g. for // tokens. $set = rules_action_set(array($entity_key => array('type' => $entity_type, 'label' => $info['label']))); $action = rules_action('component_' . $this->operationInfo['key'], array($entity_key . ':select' => $entity_key)); $set->action($action); // Embed the form of the component action, but default to "input" mode for // all parameters if available. foreach ($action->parameterInfo() as $name => $info) { $form_state['parameter_mode'][$name] = 'input'; } $action->form($form, $form_state); // Remove the configuration form element for the "entity" param, as it // should just use the passed in entity. unset($form['parameter'][$entity_key]); // Tweak direct input forms to be more end-user friendly. foreach ($action->parameterInfo() as $name => $info) { // Remove the fieldset and move its title to the form element. if (isset($form['parameter'][$name]['settings'][$name]['#title'])) { $form['parameter'][$name]['#type'] = 'container'; $form['parameter'][$name]['settings'][$name]['#title'] = $form['parameter'][$name]['#title']; } // Hide the switch button if it's there. if (isset($form['parameter'][$name]['switch_button'])) { $form['parameter'][$name]['switch_button']['#access'] = FALSE; } } return $form; }
/** * Test using field collection items via the host while they are being created. */ public function testUsageDuringCreation() { // Test using a single-cardinality field collection. $this->createFields(1); $node = $this->drupalCreateNode(array('type' => 'article')); $entity = entity_create('field_collection_item', array('field_name' => $this->fieldName)); $entity->setHostEntity('node', $node); // Now the field collection is linked to the host, but not yet saved. // Test using the wrapper on it. $wrapper = entity_metadata_wrapper('node', $node); $wrapper->get($this->fieldName)->field_text->set('foo'); $this->assertEqual($entity->field_text[LANGUAGE_NONE][0]['value'], 'foo', 'Field collection item used during creation via the wrapper.'); // Now test it via Rules, which should save our changes. $set = rules_action_set(array('node' => array('type' => 'node', 'bundle' => 'article'))); $set->action('data_set', array('data:select' => 'node:' . $this->fieldName . ':field-text', 'value' => 'bar')); $set->execute($node); $this->assertEqual($entity->field_text[LANGUAGE_NONE][0]['value'], 'bar', 'Field collection item used during creation via Rules.'); $this->assertTrue(!empty($entity->item_id) && !empty($entity->revision_id), 'Field collection item has been saved by Rules and the host entity.'); RulesLog::logger()->checkLog(); }