D7 Create Custom CT's - pierregermain/MyDrupal GitHub Wiki
D7 Creación de Content Types llamado Friend desde un módulo
1. Creamos la estructura del módulo
//*.module
/**
* Implements hook_node_info()
*/
function friend_node_info() {
return array(
'friend' => array(
'name' => t('Friend'),
'base' => 'friend',
'description' => t('You can define new Friends here'),
'has_title' => TRUE,
'title_label' => t('Friend title')
)
);
}
/**
* Implement hook_form()
*/
function friend_form($node, $form_state) {
return node_content_form($node, $form_state);
}
//*.install
/**
* Implements hook_install().
*/
function friend_install() {
node_types_rebuild();
$types = node_type_get_types();
}
//*.uninstall
/**
* Implements hook_uninstall().
*/
function friend_uninstall() {
// To delete all nodes from the terminal do: drush delete-all friend
$ournewtype = 'friend';
node_type_delete($ournewtype);
}
No olvides crear *.info con las dependencias
2. Usamos Features para crear la estructura de los fields.
No olvides borrar el body si no lo necesitas.
Para el caso de los fields tendrás dos ficheros:
*.features.field_instance.inc
*.features.field_base.inc
3. Meter los fields en el *.install
function _friend_installed_fields() {
// Aqui retornamos el array del fichero field_base.inc haciendo ciertos cambios a la sintaxis para poderlo usar posteriormente
}
function _friend_installed_fields() {
// Aqui retornamos el array del fichero field_instance.inc haciendo ciertos cambios a la sintaxis para poderlo usar posteriormente
}
function add_custom_fields() {
(…)
}
/**
* Implements hook_install().
*/
function friend_install() {
node_types_rebuild();
$types = node_type_get_types();
add_custom_fields();
}
4. Probar módulo
kbox drush site-install -y --db-url=mysql://drupal:drupal@database:3306/drupal --account-name=admin --account-pass=admin
kbox drush -y en friend
// Hacer Pruebas
drush delete-all friend
drush dis friend
Crear Contenido
drush en devel
drush en devel_generate
drush genc 50 --types=friend