I trying to create a drupal module, but when I go on page /polcode I get this notice:
Access denied
You are not authorized to access this page.
This is my module:
<?php
// $Id$
/**
* #file
* A module exemplifying Drupal coding practices and APIs.
*
* This module provides a block that lists all of the
* installed modules. It illustrates coding standards,
* practices, and API use for Drupal 7.
*/
/**
* Implements hook_menu().
*/
function polcode_menu()
{
$items['polcode'] = array
(
'title' => 'tytuł',
'description' => 'opis',
'page callback' => 'drupal_get_form',
'page arguments' => array('input_simple_form'),
'access calback' => TRUE,
);
return $items;
}
/*
* Form
*/
function input_simple_form($form, &$form_submit)
{
$form['color'] = array
(
'#title' => t('Color'),
'#type' => 'textfield',
'#required' => TRUE,
'#description' => t('Opis'),
);
$form['submit'] = array
(
'#type' => 'submit',
'#value' => 'submit',
);
return $form;
}
I had cleared cache, and enable module in backend, also I'm loged in as admin, what's wrong?
And this is info:
;$Id$
name = polcode
description = A first module.
package = Drupal 7 Development
core = 7.x
files[] = polcode.module
;dependencies[] = autoload
;php = 5.2
You misspelled access callback, change it from:
'access calback' => TRUE,
to be:
'access callback' => TRUE,
Related
I have a site on Drupal 8.6 and Bootstrap 3.3.7
I created a custom module for the customer to accept the terms and conditions of the store when placing an order.
This displays a link to a checkbox before payment to display the terms and conditions in a modal window.
When I place an order here are the warnings in the logs (sorry my code is too long to be published here):
https://pastebin.com/1p5m1Ved
https://pastebin.com/XYbqDJje
https://pastebin.com/P93bStKh
Here is the file that created the problem :
<?php
namespace Drupal\commerce_marketplace_terms_and_conditions\Plugin\Commerce\CheckoutPane;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Form\FormStateInterface;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Provides the completion message pane.
*
* #CommerceCheckoutPane(
* id = "marketplace_terms_and_conditions",
* label = #Translation("Marketplace Terms and Conditions"),
* default_step = "review",
* )
*/
class MarketplaceTermsAndConditions extends CheckoutPaneBase implements CheckoutPaneInterface {
/**
* {#inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$store_name = $this->order->getStore()->getName();
$store_id = $this->order->getStoreId();
$pane_form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$attributes = [
'attributes' => [
'class' => 'use-ajax',
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => auto
]),
],
];
$link = Link::fromTextAndUrl(
$this->t('terms and conditions of the store "#store_name"', ['#store_name' => $store_name]),
Url::fromUri("internal:/store/$store_id/cgv", $attributes)
)->toString();
$pane_form['marketplace_terms_and_conditions'] = [
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' => $this->t('I have read and accept #terms.', ['#terms' => $link]),
'#required' => TRUE,
'#weight' => $this->getWeight(),
];
return $pane_form;
}
}
What's wrong with my custom module and how to fix the problem ? Thank you
Change this to
'width' => auto
this
'width' => 'auto'
It is assuming it to be a constant, as you can see from the errors, it has to be either a variable or a string.
I am trying to create and enable a module in Drupal 7.59 and I am getting below issue on admin page.
This version is not compatible with Drupal 7.x and should be replaced.
The module name is "events" and the .info file content is
name = Events Creation
description = This module will create media events
core = 7.59
And events module code is
<?php
function events_menu() {
$items = array();
$items['test/events'] = array( //this creates a URL that will call this form at "examples/form-example"
'title' => 'Event Creation Form', //page title
'description' => 'A form to create an event.',
'page callback' => 'drupal_get_form', //this is the function that will be called when the page is accessed. for a form, use drupal_get_form
'page arguments' => array('events_form'), //put the name of the form here
'access callback' => TRUE
);
return $items;
}
function events_form($form, &$form_state) {
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Click Here!'),
);
return $form;
}
function events_form_validate($form, &$form_state) {
}
function events_form_submit($form, &$form_state) {
}
Any help is highly appreciated. Thanks in advance.
Sorry my mistake. It would be core = 7.x
I have create module for uploading files into database, and only administrator can upload that files. So I have hook_permission for administer to upload files:
function upload_permission() {
return array(
'administer uploader' => array(
'title' => t('Administer Uploader'),
'description' => t('Allow the following roles to upload files files to the server.'),
),
);
}
Also I create several custom nodes with path files/node/% and now I need permission for anonymous users to see page with custom nodes. Below I add this permission:
'access files/node/%' => array(
'title' => t('Access Files'),
'description' => t('Access Files.'),
),
and still don't work. Is there any other solution how anonymous user can view the page with custom nodes ?
As far I know, just check the permission "view published content" in the CMS permission page that should be checked for the anonymous user role. For viewing a Drupal node no specific permission needed until you are using any individual node permission settings. Also, for your custom node path please use the below settings array in your hook_menu to make all path works with the URL 'files/node/%'.
/**
* Implements hook_menu().
*/
function yourmodule_menu() {
$items = array();
$items['files/node/%'] = array(
'title' => 'Files node',
'page callback' => '_yourmodule_page_callback',
'page arguments' => array(2),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
Just notice the below line of code, this say that anyone with the permission 'access content' (View published content) can see these node.
'access arguments' => array('access content'),
Hope this will help you!
I've been using this guide to develop a Drupal 7 module.
I want this module to simply display them to an administrator who can then change and accept them from there. I can get my module to appear in the Modules section but when I enable it, the form and menu item I built are not where they should be. There is no menu item in the Configuration section so I can't navigate to the form I made. Here's my .module:
/**
* Implements hook_help.
*
* Displays help and module information.
*
* #param path
* Which path of the site we're using to display help
* #param arg
* Array that holds the current path as returned from arg() function
*/
function moderate_submissions_help($path, $arg) {
switch ($path) {
case "admin/help#moderate_submissions":
return '<p>' . "Allows admins to moderate new pending submissions." . '</p>';
break;
}
}
/**
* Implements hook_menu().
*/
function moderate_submissions_menu() {
$items = array();
$items['admin/config/content/moderate_submissions'] = array(
'title' => 'Moderate Submissions',
'description' => 'Go through submissions.',
'page callback' => 'drupal_get_form',
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
}
/**
* Page callback: Settings
*
* #see moderate_submissions_menu()
*/
function moderate_submissions_form($form, &$form_state) {
$form['moderate_submissions_max'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of posts'),
'#size' => 2,
'#maxlength' => 2,
'#description' => t('The maximum number of links to display in the block.'),
'#required' => TRUE,
);
return system_settings_form($form);
}
And my .info:
name = Moderate Submissions
description = Moderate pending goal submissions.
core = 7.x
configure = admin/config/content/moderate_submissions
This is probably the result of something I overlooked in trying to adapt the tutorial to what I'm building.
moderate_submisisons_menu() needs to return $items.
I trying to get the twitter_admin_form and twitter_user_settings form in a div.
/**
* Get twitter form for user
* #param $account
* #type user object
*/
function getTwitterForm($account){
//module_load_include('inc', 'twitter');
module_load_all();
$twitter_form = drupal_get_form('twitter_admin_form');
return $twitter_form;
}
I get a get a drupal error.
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'twitter_admin_form' was given in .../includes/form.inc on line 372.
twitter.module
/**
* Implementation of hook_meu()
*/
function twitter_menu() {
$items = array();
$items['admin/settings/twitter'] = array(
'title' => 'Twitter setup',
'description' => 'Twitter module settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('twitter_admin_form'),
'access arguments' => array('administer site configuration'),
'file' => 'twitter.pages.inc'
);
$items['user/%user_category/edit/twitter'] = array(
'title' => 'Twitter accounts',
'page callback' => 'twitter_user_settings',
'page arguments' => array(1),
'access arguments' => array('add twitter accounts'),
'load arguments' => array('%map', '%index'),
'weight' => 10,
'file' => 'twitter.pages.inc',
'type' => MENU_LOCAL_TASK,
);
return $items;
}
I'm not sure what I'm doing wrong. The twitter_admin_form doesn’t have any arguments hence I thought it would be simple to get and display.
I’m new forms/menu so I’m not 100% sure what %user_category, %map and %index are and how to pass them in.
How do you know what the valid forms are?
When you call drupal_get_form you supply a form id, which is the function that Drupal needs to call. The problem you are experiencing is that Drupal cannot find the function: twitter_admin_form.
Either it's located in an include file, and you need to include it, or you have named it something else.
The error you get stems from the line:
$twitter_form = drupal_get_form('twitter_admin_form');
It expects 'twitter_admin_form' to be a valid callback function, but can't find it. This is probably because the related file 'twitter.pages.inc' is not included at the time of your call.
You could fix that via a:
module_load_include('inc', 'twitter', 'twitter.pages');
(Given the commented line in your code sample, you seem to have tried something like this, but forgot to give the name of the file to include).