change drupal comment - drupal

I want to put the comment textarea which is used to enter the comment text above the three fields (name, email, homepage). The final result should be as shown below:
the comment text area
name: email: homepage: submitcomment
how I position the fields like this? Thank you.
the version is drupal 6.20. i mean the form to create a comment.

To modify the comment form the way you want to you're probably going to want to use a hook_form_alter() to modify the formfield weights. You can theme it with by providing a preprocess function (see: http://systemseed.com/blog/how-customise-comment-form-drupal-6) but to rearrange the formfield weights I think you'll need to use hook_form_alter() in a little custom module.
Something like this:
in MY_MODULE.module
/**
* Implementation of hook_form_alter().
*/
function MY_MODULE_form_alter(&$form, &$form_state, $form_id){
if ($form_id == 'comment_form'){
$form['comment_filter']['#weight'] => -10
);
}
}
Other than that you could resort to something simpler with jQuery to just rearrange divs on page load

Related

How can I add a paragraph (as default) in the node form by using hook_form_alter in Drupal 8?

I am trying to add a bunch of different empty paragraphs of different types, to a entity reference revisions field, everytime a node of a certain content type is created.
I DON'T want to use the contrib module "default paragraphs" for this, because I need to use a certain form widget here, and default paragraphs is also achieved by a widget.
What I tried so far:
function myModule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
$paragraph = \Drupal\paragraphs\Entity\Paragraph::create([
'type' => 'tab_features'
]);
$paragraph->save();
$form['field_tabs']['widget'][0]['target_id']=$paragraph->id();
$form['field_tabs']['widget'][0]['target_revision_id']=$paragraph->getRevisionId();
return $form;
}
$field_tabs is my entity reference revisions field.
'tab_features' is the paragraphs type I want to add.
I guess there should be a method that can be used in the form or form widget to add a paragraph to the form, like someone already clicked the button to add it. I want to avoid to actually trigger this via Javascript if possible. Anybody knows how to do this in form_alter?
In a project I'm working on, we have done something like this:
//get the body field
$field = $entity->get('field_em_p_body');
$paragraph = Paragraph::create([
'type' => 'em_section', // Paragraph type.
]);
$paragraph->isNew();
$paragraph->set('YOUR_FIELD', 'SOMETHING');
$field->appendItem($paragraph);

How to customize the form of SonataAdminBundle

For example I would like to do this.
A. Show map instead of latitude and altitude property.
B. Show thumbnails of pictures instead of select box for pictures.
I can do this kind of things for list screen like this below.
public function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('map',null,array('template' => 'AcmeAdminBundle:MyTemplate:list_map.html.twig',
'property_path' => false
))
After overriding the template and then it is possible to show the map or do some complex things in my original list_map.html.twig
Now I want to try the same thing with Form though,'FormMapper' doesn't have 'template' option.
So, I override the form_admin_fields.html.twig and edit someplaces but it doesn't change the each objects of form.
Even I delete all of code in form_admin_fields.html.twig. (makes the blank file)
It just changes the layout of form.
I would like to customize each text box or select box of form.
Where should I start to customize form page in SonataAdminBundle??
Try to create custom field type for this, like here

Drupal 7 - Taxonomy terms hierarchy hook function

As you know there is an admin page for setting up hierarchy of terms by dragging it, which can be found on admin/structure/taxonomy/your_vocabulary. Underneath the table there are two buttons "Save" and "Reset to alphabetical". Now I need to interact with those sumbits by using some hook but I've no idea how to do it. I've already tried hook_taxonomy_term_presave() and hook_taxonomy_term_update(), but those are definitely not appropriate. Any ideas how to hook it?
You can do all your stuff by adding additional callback in submit.
e.g:
/**
* Implements hook_form_FORM_ID_alter().
*/
function hook_form_taxonomy_form_vocabulary_alter(&$form) {
$form['#submit'][] = 'my_function';
}
function my_function(&$form, &$form_state) {
// Do something ..
}

drupal theme checkboxes

I'm trying to us the theme hook the style some checkboxes. I have used the form_alter hook to make some changes to the labels of each checkbox and now i would like to interact with the checkbox theme function to style the labels.
In the form array it says
#theme (String, 20 characters ) select_as_checkboxes
is this the function i need to override? And how do i do this?
I tried stuff like
function mymodule_select_as_checkboxes()
but i can't get it to work
Solution:
function my_module_theme_registry_alter(&$theme_registry) {
// Register theme_function to use the module custom function
if (!empty($theme_registry['select_as_checkboxes'])) {
$theme_registry['select_as_checkboxes']['function'] = 'my_module_select_as_checkboxes';
}
}
Then in the function my_module_select_as_checkboxes create your own function or adapt the original one.

remove "profile" admin-menu from administrative panel

I am using WordPress, and I want to remove "profile" menu-option completely
Any one is having idea how can I achieve this?
Thanks
For the sake of completeness, here's how to do it programmatically...
// Run the function on admin_init
add_action('admin_init', 'remove_profile_menu');
// Removal function
function remove_profile_menu() {
global $wp_roles;
// Remove the menu. Syntax is `remove_submenu_page($menu_slug, $submenu_slug)`
remove_submenu_page('users.php', 'profile.php');
/* Remove the capability altogether. Syntax is `remove_cap($role, $capability)`
* 'Read' is the only capability subscriber has by default, and allows access
* to the Dashboard and Profile page. You can also remove from a specific user
* like this:
* $user = new WP_User(null, $username);
* $user->remove_cap($capability);
*/
$wp_roles->remove_cap('subscriber', 'read');
}
I know this is late but I just stumbled on this and thought I would add to it. That does remove the sub-menu profile menu item but does not remove the menu profile item. For someone like me who has created a completely custom profile page, I don't want my users to access the profile.php page at all. So this code will work for that:
function remove_profile_menu() {
remove_submenu_page('users.php', 'profile.php');
remove_menu_page('profile.php');
}
add_action('admin_menu', 'remove_profile_menu');
And if you only want to do this for certain capabilities....use this code:
function remove_profile_menu() {
// Only the Admin can see the profile menu
if(!current_user_can('update_core')) {
remove_submenu_page('users.php', 'profile.php');
remove_menu_page('profile.php');
}
}
add_action('admin_menu', 'remove_profile_menu');
You can use the current_user_can() function to determine who you want to see the menu items.
Profiless plugin does that on the subscriber-level.
If you wish to do that for other groups, you should probably use it in combination with Capability manager plugin.

Resources