Ejemplo n.º 1
0
 /**
  * @Given that the widget for the :field_name field of the :bundle :entity_type is changed to :widget_type_machine_name
  *
  * Behat is not very good at filling in form fields that are taxonomy
  * term trees, or checkboxes.  The reason for this is that Behat is
  * overly energetic about regularly deleting and recreating all of the
  * test content, sometimes even in the middle of a scenario.  The result
  * of this is that the term ids all change between the time the checkbox
  * is "clicked", and the time the form is submitted, leading to a validation
  * error.  With this step definition, we can change taxonomy checkbox
  * fields into autocomplete forms, which Behat fills in with a String value
  * rather than a term id -- which works consistently.
  *
  * Example:
  *     "Given that the widget for the offices field of the regnum entityform is changed to taxonomy_autocomplete"
  *     "And the cache has been cleared"
  *
  * http://dropbucket.org/node/1265
  */
 function change_form_widget($entity_type, $bundle, $field_name, $widget_type_machine_name)
 {
     // Retrieve the stored instance settings to merge with the incoming values.
     $instance = field_read_instance($entity_type, $field_name, $bundle);
     // Set the right module information.
     $widget_type = field_info_widget_types($widget_type_machine_name);
     $widget_module = $widget_type['module'];
     $instance['widget']['type'] = $widget_type_machine_name;
     $instance['widget']['module'] = $widget_module;
     // Update field instance
     field_update_instance($instance);
 }
Ejemplo n.º 2
0
 public static function load($field_name, $entity_type, $bundle)
 {
     $data = \field_read_instance($entity_type, $field_name, $bundle);
     $class = \get_called_class();
     return new $class($data);
 }
Ejemplo n.º 3
0
 /**
  * Adds availability reference field to a content type.
  *
  * @When /^I add the "(?<field_name>[^"]*)" availability reference field referencing to "(?<unit_types>[^"]*)" units in "(?<content_type>[^"]*)" content$/
  */
 public function iAddTheAvailabilityReferenceFieldReferencingToUnitsInPageContent($field_name, $unit_types, $content_type)
 {
     // Create the content type.
     // Make sure a testimonial content type doesn't already exist.
     if (!in_array($content_type, node_type_get_names())) {
         $type = array('type' => $content_type, 'name' => $content_type, 'base' => 'node_content', 'custom' => 1, 'modified' => 1, 'locked' => 0);
         $type = node_type_set_defaults($type);
         node_type_save($type);
         node_add_body_field($type);
         $this->content_types[] = $content_type;
     }
     // Create field ('rooms_booking_unit_options') if not exist.
     if (field_read_field($field_name) === FALSE) {
         $field = array('field_name' => $field_name, 'type' => 'rooms_availability_reference', 'cardinality' => -1, 'settings' => array('referenceable_unit_types' => drupal_map_assoc(explode(',', $unit_types))));
         field_create_field($field);
         $this->fields[] = $field_name;
     }
     if (field_read_instance('node', $field_name, $content_type) === FALSE) {
         // Create the instance on the bundle.
         $instance = array('field_name' => $field_name, 'entity_type' => 'node', 'label' => 'Availability reference', 'bundle' => $content_type, 'required' => FALSE, 'widget' => array('type' => 'rooms_availability_reference_autocomplete'));
         field_create_instance($instance);
     }
 }
Ejemplo n.º 4
0
 /**
  * TODO write documentation.
  * @param $field_name
  * @param $widget_type
  * @param $display_type
  * @param $bundle
  * @return unknown_type
  */
 protected function drupalCreateFieldInstance($field_name, $widget_type, $formatter_type, $bundle)
 {
     $instance_definition = array('field_name' => $field_name, 'bundle' => $bundle, 'widget' => array('type' => $widget_type), 'display' => array('full' => array('type' => $formatter_type)));
     field_create_instance($instance_definition);
     $instance = field_read_instance($field_name, $bundle);
     $this->assertTrue($instance, t('Created instance of field @field_name on bundle @bundle.', array('@field_name' => $field_name, '@bundle' => $bundle)));
     return $instance;
 }