You are here

public function FeatureContext::iAddTheAvailabilityReferenceFieldReferencingToUnitsInPageContent in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

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$/

File

test/features/bootstrap/FeatureContext.php, line 807

Class

FeatureContext
Features context.

Code

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);
  }
}