Opensource, CMS, PHP, MySql, Drupal, Frameworks

Thursday, November 23, 2017

Render node form in custom page

            <?php
                  global $user;
                  $type = 'smartbits';
                  $node = (object) array(
                    'uid' => $user->uid,
                    'name' => (isset($user->name) ? $user->name : ''),
                    'type' => $type,
                    'language' => LANGUAGE_NONE,
                  );
                  $form_state['build_info']['args'] = array($node);
                  form_load_include($form_state, 'inc', 'node', 'node.pages');
                  $form = drupal_build_form($type . '_node_form', $form_state);
                  print drupal_render($form);
                ?>   

Tuesday, May 28, 2013

Drupal - Own Administration Section

demo.module 

function demo_menu(){
    $items['admin/config/demo'] = array(
        'title' => 'Node demo',
        'description' => 'Adjust node demo options',
        'position' => 'right',
        'weight'=> -5,
        'page callback' => 'system_admin_menu_block_page',
        'access arguments' => array('administer site configuration'),
        'file' => 'system.admin.inc',
        'file path' => drupal_get_path('module', 'system'),
    );

    $items['admin/config/demo/settings'] = array(
        'title' => 'demo Settings',
        'description' => 'Change how demo behave',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('demo_admin_settings'),
        'access arguments' => array('administer site configuration'),
        'type' => MENU_NORMAL_ITEM,
        'file' => 'demo_posts.inc'
    );

    return $items;
}


demo_posts.inc

function demo_admin_settings($form, &$form_state){
    $types = node_type_get_types();
    foreach($types as $node_type) {
        $options[$node_type->type] = $node_type->name;
    }
    $form['demo_node_types'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Users may demo these content types'),
        '#options' => $options,
        '#default_value' => variable_get('demo_node_types', array('page')),
        '#description' => t('A text field will be available on these content types
        to make user-specific notes.'),
    );
   
    $form['#submit'][] = 'demo_admin_settings_submit';
    return system_settings_form($form);
}


Output: