コード例 #1
0
ファイル: og_testcase.php プロジェクト: jiva-technology/smcuk
 function addNodeType()
 {
     $type = new stdClass();
     $name = strtolower($this->randomName());
     $type->type = trim($name);
     $type->name = trim($name);
     $type->orig_type = trim("");
     $type->old_type = $type->type;
     $type->description = $this->randomName(32, "description ... ");
     $type->help = $type->description = $this->randomName(32, "help ... ");
     $type->min_word_count = 0;
     $type->title_label = "Title";
     $type->body_label = "Body";
     $type->module = 'node';
     $type->has_title = $type->has_body = TRUE;
     $type->custom = "";
     $type->modified = TRUE;
     $type->locked = TRUE;
     $status = node_type_save($type);
     $this->assertTrue(SAVED_NEW == $status, "Created node-type {$name}.");
     $this->_cleanupNodeTypes[] = $name;
     $types = variable_get('og_node_types', array());
     $types[$name] = $name;
     variable_set('og_node_types', $types);
     return $name;
 }
コード例 #2
0
 /**
  * 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));
 }
コード例 #3
0
 public function build()
 {
     $vars = get_object_vars($this);
     $vars['type'] = $vars['bundle'];
     $vars['name'] = $vars['label'];
     unset($vars['bundle']);
     unset($vars['label']);
     node_type_save((object) $vars);
 }
コード例 #4
0
 /**
  * Create test content type.
  */
 protected static function createTestContentType()
 {
     $name = self::randomName(8);
     $type = (object) array('type' => $name, 'name' => $name, 'base' => 'node_content', 'description' => '', 'help' => '', 'title_label' => 'Title', 'body_label' => 'Body', 'has_title' => 1, 'has_body' => 1, 'orig_type' => '', 'old_type' => '', 'module' => 'node', 'custom' => 1, 'modified' => 1, 'locked' => 0);
     node_type_save($type);
     node_types_rebuild();
     node_add_body_field($type);
     self::$contentType = $type;
 }
コード例 #5
0
ファイル: ContentType.php プロジェクト: ryne-andal/ablecore
 /**
  * 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);
 }
コード例 #6
0
 /**
  * Creates a custom content type based on default settings.
  *
  * @param settings
  *   An array of settings to change from the defaults.
  *   Example: 'type' => 'foo'.
  * @return object Created content type.
  */
 function drupalCreateContentType($settings = array())
 {
     // find a non-existent random type name.
     do {
         $name = strtolower($this->randomName(3, 'type_'));
     } while (node_get_types('type', $name));
     // Populate defaults array
     $defaults = array('type' => $name, 'name' => $name, 'description' => '', 'help' => '', 'min_word_count' => 0, 'title_label' => 'Title', 'body_label' => 'Body', 'has_title' => 1, 'has_body' => 1);
     // imposed values for a custom type
     $forced = array('orig_type' => '', 'old_type' => '', 'module' => 'node', 'custom' => 1, 'modified' => 1, 'locked' => 0);
     $type = $forced + $settings + $defaults;
     $type = (object) $type;
     node_type_save($type);
     node_types_rebuild();
     return $type;
 }
コード例 #7
0
 /**
  * Creates a custom content type based on default settings.
  *
  * @param $settings
  *   An array of settings to change from the defaults.
  *   Example: 'type' => 'foo'.
  * @return
  *   Created content type.
  */
 protected function backdropCreateContentType($settings = array())
 {
     // Find a non-existent random type name.
     do {
         $name = strtolower($this->randomName(8));
     } while (node_type_get_type($name));
     // Populate defaults array.
     $defaults = array('type' => $name, 'name' => $name, 'base' => 'node_content', 'description' => '', 'help' => '', 'title_label' => 'Title', 'body_label' => 'Body', 'has_title' => 1, 'has_body' => 1, 'is_new' => TRUE);
     // Imposed values for a custom type.
     $forced = array('orig_type' => '', 'old_type' => '', 'module' => 'node', 'custom' => 1, 'modified' => 1, 'locked' => 0);
     $type = $forced + $settings + $defaults;
     $type = (object) $type;
     $saved_type = node_type_save($type);
     menu_rebuild();
     node_add_body_field($type);
     $this->assertEqual($saved_type, SAVED_NEW, t('Created content type %type.', array('%type' => $type->type)));
     // Reset permissions so that permissions for this content type are available.
     $this->checkPermissions(array(), TRUE);
     return $type;
 }
コード例 #8
0
 /**
  * Implements Drupal\configuration\Config\Configuration::saveToActiveStore().
  */
 public function saveToActiveStore(ConfigIteratorSettings &$settings)
 {
     $info = (object) $this->getData();
     $info->base = 'node_content';
     $info->module = 'node';
     $info->custom = 1;
     $info->modified = 1;
     $info->locked = 0;
     node_type_save($info);
     $settings->addInfo('imported', $this->getUniqueId());
 }
コード例 #9
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);
}
コード例 #10
0
/**
 * lms_create_content_type create content type by given information.
 * 
 * @param mixed $content_type_machine_name 
 * @param mixed $content_type_display_name 
 * @param mixed $content_type_desc 
 * @return void
 */
function lms_create_content_type($content_type_machine_name, $content_type_display_name, $content_type_desc, $og_type = 'group_post_standard') {
  // 0. delete the existing type with the same name if exists
  node_type_delete($content_type_machine_name);
  // 1. Create content type firstly.

  $node_type = array(
    'type' => $content_type_machine_name,
    'name' => $content_type_display_name,
    'module' => 'node',
    'description' => $content_type_desc,
    'custom' => TRUE,
    'modified' => TRUE,
    'locked' => FALSE,
  );

  $node_type = (object)_node_type_set_defaults($node_type);
  node_type_save($node_type);

  // // 2. Add fileds to the content type
  // $instance = array(
  //   'field_name' => 'lms_node_type',
  //   'entity_type' => 'node',
  //   'bundle' => $content_type_machine_name,
  //   'label' => t('lms node name'),
  //   'description' => t('indicator of the node type'),
  //   'widget' => array(
  //     'type' => 'text_textfield',
  //     'weight' => 10,
  //   ),
  // );
  // field_create_instance($instance);
  node_types_rebuild();
  menu_rebuild();


  // set og type
  if ($og_type && $og_type != 'ommitted') {
    lms_set_content_type_as_og_group_post($content_type_machine_name, $og_type);
  }
}
コード例 #11
0
 public function synchronize(NodeInterface $node, Context $context, $dirtyAllowed = false)
 {
     /* @var $node EntityNode */
     $bundle = $node->getName();
     $object = $node->getValue();
     if (!is_array($object)) {
         $object = array();
     }
     if ($node->isMerge() && ($existing = $this->getExistingObject($node, $context))) {
         $info = array('type' => $bundle, 'custom' => false) + $object + $existing;
     } else {
         $info = array('type' => $bundle, 'custom' => false) + $object + self::$defaults + array('module' => 'node', 'orig_type' => null);
     }
     if (empty($info['name'])) {
         $context->logWarning(sprintf('%s: has no name', $node->getPath()));
         $info['name'] = $bundle;
     }
     node_type_save((object) $info);
     if ($node->hasChild('settings')) {
         $settings = $node->getChild('settings')->getValue();
         if (!is_array($settings)) {
             $context->logWarning(sprintf('%s: invalid settings structure, should be an array', $node->getPath()));
         }
     }
     foreach (self::$settings as $key => $defaultValue) {
         $variable = 'node_' . $key . '_' . $node->getBundle();
         if (isset($settings[$key])) {
             variable_set($variable, $settings[$key]);
         } else {
             variable_set($variable, $defaultValue);
         }
     }
 }
コード例 #12
0
ファイル: FeatureContext.php プロジェクト: achton/rooms
 /**
  * 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);
     }
 }