/**
  * Create a petition content type and webform user enable it.
  */
 protected function webformUserCreateType()
 {
     $type = node_type_set_defaults();
     $type->name = t('Petition');
     $type->type = 'petition';
     $type->description = t('Webform user petition type.');
     $type->title_label = t('Title');
     $type->has_title = $type->title_label != '';
     $type->base = 'node_content';
     $type->custom = TRUE;
     $type->modified = TRUE;
     // Save or reset persistent variable values.
     $variables = array('node_submitted' => 0, 'comment' => COMMENT_NODE_HIDDEN, 'webform_user' => 1, 'webform_user_default_fields' => array('webform_user_all_profile_fields' => 'webform_user_all_profile_fields'));
     foreach ($variables as $key => $value) {
         $variable_new = $key . '_' . $type->type;
         if (is_array($value)) {
             $value = array_keys(array_filter($value));
         }
         variable_set($variable_new, $value);
     }
     $status = node_type_save($type);
     node_types_rebuild();
     node_add_body_field($type);
     // Add as a webform.
     $webform_node_types = variable_get('webform_node_types', array('webform'));
     $webform_node_types_primary = variable_get('webform_node_types_primary', array('webform'));
     $webform_node_types = array_merge($webform_node_types, array('petition'));
     $webform_node_types_primary = array_merge($webform_node_types_primary, array('petition'));
     variable_set('webform_node_types', array_unique($webform_node_types));
     variable_set('webform_node_types_primary', array_unique($webform_node_types_primary));
 }
Example #2
0
 /**
  * Saves the current content type to the database.
  *
  * @throws \Exception
  */
 public function save()
 {
     // Make sure the definition is valid.
     $validation = $this->validate();
     if ($validation !== true) {
         throw new \Exception("The content type is invalid. Reason: {$validation}. Cannot save.");
     }
     $type = node_type_set_defaults($this->definition);
     node_type_save($type);
 }
Example #3
0
<?php

$types = array(array('type' => 'page', 'name' => 'Basic page', 'base' => 'node_content', 'description' => 'Use <em>basic pages</em> for your static content, such as an \'About us\' page.', 'custom' => 1, 'modified' => 1, 'locked' => 0), array('type' => 'article', 'name' => 'Article', 'base' => 'node_content', 'description' => 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.', 'custom' => 1, 'modified' => 1, 'locked' => 0));
foreach ($types as $type) {
    $type = node_type_set_defaults($type);
    node_type_save($type);
    node_add_body_field($type);
}
Example #4
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);
     }
 }