View source
<?php
function field_rules_node_type_insert($info) {
rules_invoke_event('node_type_insert', $info);
}
function field_rules_entity_info() {
return array(
'node_type' => array(
'label' => t('Node Type'),
'controller class' => 'DrupalDefaultEntityController',
'base table' => 'node_type',
'entity keys' => array(
'id' => 'type',
'name' => 'name',
),
'creation callback' => 'node_type_set_defaults',
'save callback' => 'field_rules_node_type_save',
'deletion callback' => 'node_type_delete',
),
);
}
function field_rules_entity_property_info() {
$info = array();
$properties =& $info['node_type']['properties'];
$properties['type'] = array(
'label' => t('Node type'),
'type' => 'text',
'description' => t('The machine name of this node type.'),
'setter callback' => 'entity_property_verbatim_set',
'setter permission' => 'administer content types',
'getter callback' => 'entity_property_verbatim_get',
'required' => TRUE,
'query callback' => 'entity_metadata_table_query',
);
$properties['name'] = array(
'label' => t('Name'),
'description' => t('The human readable name of this content type.'),
'setter callback' => 'entity_property_verbatim_set',
'setter permission' => 'administer content types',
'getter callback' => 'entity_property_verbatim_get',
'required' => TRUE,
'query callback' => 'entity_metadata_table_query',
);
$properties['description'] = array(
'label' => t('Description'),
'description' => t('The description of this content type.'),
'setter callback' => 'entity_property_verbatim_set',
'setter permission' => 'administer content types',
'getter callback' => 'entity_property_verbatim_get',
);
$properties['help'] = array(
'label' => t('Help'),
'description' => t('The help of this content type.'),
'setter callback' => 'entity_property_verbatim_set',
'setter permission' => 'administer content types',
'getter callback' => 'entity_property_verbatim_get',
);
$properties['has_title'] = array(
'label' => t('Has title'),
'type' => 'boolean',
'description' => t('Whether the node type has a title.'),
'setter callback' => 'entity_property_verbatim_set',
'setter permission' => 'administer content types',
'getter callback' => 'entity_property_verbatim_get',
);
$properties['has_body'] = array(
'label' => t('Has title'),
'type' => 'boolean',
'description' => t('Whether the node type has a title.'),
'setter callback' => 'entity_property_verbatim_set',
'setter permission' => 'administer content types',
'getter callback' => 'entity_property_verbatim_get',
);
$properties['title_label'] = array(
'label' => t('Title label'),
'description' => t('The label for the title of this content type.'),
'setter callback' => 'entity_property_verbatim_set',
'setter permission' => 'administer content types',
'getter callback' => 'entity_property_verbatim_get',
);
$properties['title'] = array(
'label' => t('Title'),
'description' => t('The title of the node.'),
'setter callback' => 'entity_property_verbatim_set',
'query callback' => 'entity_metadata_table_query',
'required' => TRUE,
);
return $info;
}
function field_rules_node_type_save($node_type) {
if (!isset($node_type->base)) {
$node_type->base = 'node_content';
}
$node_type = node_type_set_defaults($node_type);
node_type_save($node_type);
node_types_rebuild();
menu_rebuild();
}