0

Ive followed 3 tutorials and I cant seem to crack this. My goal is to create a form in the admin section to store some information.

I have used the following to create the form and call it from a url but I seem to be missing something

    function read_more_news_admin() {
  $form = array();
   //link field
      $form['link_container'] = array(
        '#type' => 'container',
        '#attributes' => array('class' => array('some-class')),
        '#tree' => TRUE,
      );
      $form['link_container']['link'] = array(
        '#type' => 'link_field',
        '#field_name' => 'link_field',
        '#language' => 'und',
        '#field_parents' => array(),
        '#delta' => 0,
        '#default_value' => array(
          'title' => variable_get('link_title', ''),
          'url' => variable_get('link_url', ''),
        ),
      );
  return system_settings_form($form);
}

function read_more_news_menu() {
  $items = array();
  $items['admin/settings/readmorenews'] = array(
    'title' => 'Read More News Module Settings',
    'description' => 'Set read more news outgoing link here',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('read_more_news_admin'),
    'access arguments' => array('administer readmorenews settings'),
    'type' => MENU_NORMAL_ITEM,
   );
  return $items;
}

Any help would be appreciated

  • Since the path is admin/* so therefore it must show in the admin menu, once thing you can check is the access argument of the page, the link would appear in the admin menu only if the user have access to that page so once you can check after changing the access arguments to something more simple. – Ankit Agrawal Sep 24 '14 at 15:13
  • What do you suggest for the access arguments? I was just following a tutorial that placed that there. So I dont understand how to use it properly yet. – MichaelTaylor3D Sep 24 '14 at 15:19
  • Actually access arguments contains the permission for the page, it depends upon you how you want to set the access control for that page, simplest you can try for now is 'access arguments' => array('access content'), check more here: drupal.stackexchange.com/questions/5968/… – Ankit Agrawal Sep 24 '14 at 15:21
1

try this:

function read_more_news_menu() {
    $items = array();
    $items['admin/settings/readmorenews'] = array(
        'title' => 'Read More News Module Settings',
        'description' => 'Set read more news outgoing link here',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('read_more_news_admin_form'),
        'access arguments' => array('administer readmorenews settings'),
        'type' => MENU_NORMAL_ITEM,
    );
    return $items;
}
function read_more_news_admin_form($form, &$form_state) {
    $form = array();
    $form['link_container'] = array(
        '#type' => 'container',
        '#attributes' => array('class' => array('some-class')),
        '#tree' => TRUE,
    );
    $form['link_container']['link'] = array(
        '#type' => 'link_field',
        '#field_name' => 'link_field',
        '#language' => 'und',
        '#field_parents' => array(),
        '#delta' => 0,
        '#default_value' => array(
            'title' => variable_get('link_title', ''),
            'url' => variable_get('link_url', ''),
        ),
    );
    return system_settings_form($form);
}

Or check this url: https://www.drupal.org/node/1111260

function read_more_news_permission() {
  return array(
    'administer my module' => array(
      'title' => t('administer readmorenews settings'),
      'description' => t('Administer read more news settings.'),
    ),
  );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.