is there a way to cleanly override the function "form_execute_handlers(...)" which is found in /includes/form.inc ?
The problem is that there are some handler-functions like "user_profile_form_validate(...)" in /modules/user/user.pages.inc which cannot be found by the core version of "form.inc", since the following statement is missing in "form_execute_handlers(...)" for this special case:
module_load_include('inc', 'user', 'user.pages');
I would like to add that somehow, and therefore override form.inc ;)
Ok, I found a way to include the library (inside my custom module):
function wr_pages_init() {
if (($_GET['q'] == 'system/ajax' || strstr($_GET['q'], 'file/ajax/')) && $_POST['form_id'] == "user_profile_form") {
module_load_include('inc', 'user', 'user.pages');
}
}
Never change core functionality! Updating drupal will override your changes and is not good practice at all. Keep in mind that all other modules uses core too so things goes really wrong if you mess with core.
You can do custom user form like this (link to other answer):
drupal 7 cusomized user profile template can not save changes
There is also hooks for altering form handling. So you can change user form validation like this:
hook_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_profile_form') {
$form['#validate'][] = 'your_validation_function';
}
}
Or if you want only to use your own validation change:
$form['#validate'] = array('your_validation_function');
You don't have to check queries when including user library. Just include it like:
function wr_pages_init() {
module_load_include('inc', 'user', 'user.pages');
// And other includes (if needed) same way.. like:
// Add jquery ui libraries..
drupal_add_library('system', 'ui');
drupal_add_library('system', 'ui.sortable');
drupal_add_library('system', 'ui.datepicker');
// Add ajax..
drupal_add_library('system', 'drupal.ajax');
// Some own JS
drupal_add_js(drupal_get_path('module', 'wr_pages') . '/js/mysuper.js', 'file');
}
Related
I'm using Cakephp 2.4.3 . I've read that "There are CakePHP plugins that are able to generate sitemaps for you. This way your sitemap.xml file will be created dynamically on demand and will always be up to date." . I've searched but all I find are from old cakephp version which is not useful as they only cause errors .
Is there still a good plugin for this?
Some plugins definitely exist:
https://github.com/sdevore/cakephp-sitemap-plugin
https://github.com/smarek/Croogo-Sitemap-2.0
https://github.com/webtechnick/CakePHP-Seo-Plugin
Are these the old, error-causing ones? As each CakePHP site can be radically different to the next, I'm not sure a one-size-fits-all solution will exist.
If you end up writing your own sitemap implementation, it'll depend mainly on whether your site has:
Lots of database-driven content with few controllers/actions (like a typical WordPress-style site)
Lots of controller/action driven content (more of a web application)
In the first case, you'd want to perform finds on your content, and inject the results into an xml template like this: http://bakery.cakephp.org/articles/masterkeedu/2008/08/26/automatically-generate-dynamic-sitemaps
For the second case, the following may help: a component I've used for development/testing, which lists all controllers and their methods:
<?php //File: app/Controller/Component/CtrlComponent.php
// Component rewritten for Cake2.x, original from : http://cakebaker.42dh.com/2006/07/21/how-to-list-all-controllers/
class CtrlComponent extends Component {
/**
* Return an array of Controllers and their methods.
* The function will exclude ApplicationController methods
* #return array
*/
public function get() {
$aCtrlClasses = App::objects('controller');
foreach ($aCtrlClasses as $controller) {
if ($controller != 'AppController') {
// Load the controller
App::import('Controller', str_replace('Controller', '', $controller));
// Load its methods / actions
$aMethods = get_class_methods($controller);
foreach ($aMethods as $idx => $method) {
if ($method{0} == '_') {
unset($aMethods[$idx]);
}
}
// Load the ApplicationController (if there is one)
App::import('Controller', 'AppController');
$parentActions = get_class_methods('AppController');
$controllers[$controller] = array_diff($aMethods, $parentActions);
}
}
return $controllers;
}
}
In reality, a full sitemap probably uses both methods, and you'll need to consider the difference between public and "private" areas of your site (excluding admin prefixes, for example)..
I have an application in which we give a very friendly interface for managing data. This is done through many controllers' add/edit/view functions. But now the requirement has come that we should have "super admins" able to edit anything, and scaffolding will give them a quick and dirty manner of changing data. Since scaffolding uses add/edit/view by default, I've unintentionally overwritten the ability to scaffold.
I can't just go and change all my calls to edit/add for our "user friendly" data managing. So I want to essentially ignore the add/edit/view when, for example, a user has a flag of "yes, please let me scaffold". I imagined it would be something like:
public function edit($id) {
if (admin_user) {
$scaffold;
} else {
[user-friendly version code]
}
}
But no dice. How can I achieve what I want?
suppose you already have admin users and you want to scaffold only super-user:
Also suppose you store the information about beeing a super-user or not in a column named super in the users table
in your core.php
Configure::write('Routing.prefixes', array('admin', 'super));
in your appController
public $scaffold = 'super';
beforFilter() {
if($this->Auth->user('super') && !isset($this->params['super'])
$this->redirect(array('super' => true));
}
Now I can't try this code but the idea should work.
edit: we need to check if we are already in a super_action to avoid infinite redirect
I'd like to change the text of the default '-Any-' that Drupal 7 views uses for an exposed dropdown filter.
Based on an answer in this thread,
How to change the label of the default value (-Any-) of an exposed filter in Drupal Views?
I have created a module called any_exposed with a hook form alter:
function any_exposed_form_alter(&$form, &$form_state, $form_id) {
if ($form['#id'] == 'views-exposed-form-vendors-page') {
$form['field_vendor_type_tid']['#options']['ALL'] = t('Everything'); } }
But all that does is add another option for 'Everything' in the dropdown, it does not overwrite/translate '-Any-'. Just to test I added:
$form['submit']['#value'] = t('Search');
Which changes the text of the Submit button from 'Apply' to 'Search', and this works fine. In case you can't tell, I'm not much of a programmer, but I figure I must be missing something simple. Any help would be appreciated!
This is an old post but in case you are still looking or for anybody who comes to this searching for an answer. 'ALL' must be 'All' as in
$form['field_vendor_type_tid']['#options']['All'] = t('Everything');
Since the array has a member 'All' but not 'ALL' (case is important here) you are adding a member 'ALL' while you want to overwrite 'All'.
Use hook_form_views_exposed_form_alter instead hook_form_alter.
function hook_form_views_exposed_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'views_exposed_form') {
$form['tid']['#options']['All'] = t('Search');
}
}
function any_exposed_form_alter(&$form, &$form_state, $form_id) {
if ($form['#id'] == 'views-exposed-form-vendors-page') {
$form['field_vendor_type_tid']['#options']['ALL'] = t('Everything'); } }
Works perfectly after changing ALL to All.
I recommend using Better Exposed Filters module, it allows you to do this simply via the Views UI interface.
Install & enable the module
Edit your view, then click on 'Exposed form > Exposed form style'
Select 'Better Exposed Filters'
Click 'More options'
Change the value of 'Override "Any" option label'
I have made a custom afterFind function in a model, but I just want it to execute it if NOT in admin mode.
public function afterFind($results) {
if(Configure::read('Routing.admin')){
return $results;
}else{
return $this->locale(&$results);
}
}
But it doesn't seems to work. I'm thinking this might not be possible. Any idea?
checking on the core Configure settings doesnt make sense to me.
besides the fact that that 'Routing.admin' is deprecated - its Prefix.admin.
it only stores the prefixes that cake uses.
If you really want to you can store the information in configure::read() in beforeFilter() of your AppController and read it from your model again.
But it would need to something that does not conflict with your settings.
So if you use Prefix you probably could use Routing again:
//beforeFilter - prior to any model find calls!
$isAdmin = !empty($this->params['admin']);
Configure::write('Routing.admin', $isAdmin);
the other option you always have is to pass the information on to the model.
Router::getParam('prefix', true) gives you current request prefix value.
public function afterFind($results, $primary = false) {
return Router::getParam('prefix', true) == 'admin' ? $results : $this->locale(&$results);
}
Tested with Cake 2.4.
I'm building a module using hook_preprocess_node()
I've made a new view mode for the node entity called ´vacancy_teaser´ using the hook_entity_info_alter()
this shows up in my node display settings and view
so I want to use the template included in my module when this view mode is used.
my code:
/**
* Implements hook_preprocess_node().
*/
function vacancies_preprocess_node(&$vars) {
if($vars['view_mode'] == 'vacancy_teaser') {
$vars['theme_hook_suggestions'][] = 'node_vacancy_teaser';
}
}
my template file is called: ´node-vacancy-teaser.tpl.php´ but is not used in the output of my view
$vars['view_mode'] == 'vacancy_teaser' in the view. ( tested )
but where does $vars['theme_hook_suggestions'][] = 'node_vacancy_teaser'; looks for the template file? somehow it's not included / used.
apparently in drupal 7 useing dubble underscores is required for some reason.
node_vacatures_vacancy_teaser.tpl.php placed in the active template folder seems to do the trick... although I don't think this is a neat solution since the tpl.php file is separated from the module.
Be sure to specify the template file in the hook_theme implementation. The examples project is great for finding out the details of how to do things like this. Specifically, check out the theming_example_theme() function in the theming_example module…
function theming_example_theme() {
return array(
// …
'theming_example_text_form' => array(
'render element' => 'form',
// In this one the rendering will be done by a tpl.php file instead of
// being rendered by a function, so we specify a template.
'template' => 'theming-example-text-form',
),
);
}
Instead of appending to the end of the $vars['theme_hook_suggestions'] array, try:
array_unshift($vars['theme_hook_suggestions'], 'node_vacancy_teaser');
This will pass your suggestion to the front of the array, and it will be found first. Most likely since you are appending it to the end of the array, Drupal is finding an existing theme suggestion first and using it instead (such as node.tpl.php).