Drupal 7: Modifying menu HTML output? - drupal-7

I am trying to modify the HTML output in a Drupal 7 theme that I am creating.
Basically, instead of the < li >s containing just plain < a >s with text, I want to include some additional HTML inside the < a >.
I know that it's possible to modify the HTML created by the menus in Drupal. I can see the following call in page.tpl.php:
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu',
'class' => array('links', 'clearfix'),
),
'heading' => array(
'text' => t(''),
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
which apparently calls the theme function, which creates the output. One way to modify the output would be to modify the theme_links function in theme.inc, right?
http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_links
I also know that you can put a hook in template.php to override the function which creates the HTML. I can't figure out how to create the actual override function. Can somebody point me in the right direction, please?

What you would do is implement a hook to modify the output, not modify the "theme.inc" file directly.
For example, the accepted answer on this page: Drupal Override Custom Menu Template
And as a general rule, when you want to modify the output of something, either implement a hook (in a module or in the template.php of the active theme) or use a template with a predefined file name when such a case exists (when no template already exists, you can also modify the list of template suggestions using a module or the theme).

Related

Separate navigation menu from default.ctp in CakePHP

I am working on CakePHP 2.7. I have to show some static menu on every page. Since, the menu contains lot of sub menus, I want to keep them in a separate file navigation.ctp and show them on default.ctp
I tried extend and elements but none of them give expected result.
Note : This is not dynamic menu and I am not fetching them from database.
Place your navigation.ctp inside app/View/Elements/
Then, inside your default.ctp, include the element as follows:
<?= $this->element('navigation'); ?>
Note that if you need any variables within the element, you may need to pass them through inside an array as a second parameter, such as:
<?= $this->element('navigation', array(
"varible_name" => "variable_value"
)); ?>

ExtJS 5 Dynamically chage a Hyberlink

I'm having some issue of using ExtJS-5 to set some Hyberlink which also could be dynamically changed(according to a REST GET call).
Now I'm able to set a label as a Hyberlink using it's 'html' config which makes it clickable and jump to another page. Also according to the DOC file, if I assign the 'text' config to a 'Label' it will disable the 'html' property and only display the 'text'. So now I can change the 'text' of label Dynamically but they are not clickable.
Questions:
Should I use 'Label' for what I'm trying to do or use something else?
DOC shows 'Label' has no getText or getHTML method, then how to read its 'value'? like I want to pass it to the BackEnd. (getValue() doesn't work)
Label is perfectly fine for doing this
ExtJS doesn't provide any method of getting text value, cause we can read it directly

CakePHP Overide getCrumbList

How can I go about overiding CakePHP's code without creating it manually myself? I'm attempting to customise the getCrumbList function.
The lastClass option is applying a class to the 'li' tag sucesfully, but I'd also like to remove the link/ ahref altogether for the last tag.
Function generating crumbs
echo $this->Html->getCrumbList(array('class' => 'breadcrumb', 'lastClass' => 'active'), 'Home');
Output of getCrumbList
<ul class="breadcrumb"><li class="first">Home</li><li>Scheduler</li><li class="active">Downloaded Playlists</li></ul>
Simple solution - You dont include the URL in addCrumb. Doh!

In CakePHP 2 how to insert input field without creating form?

I'd like to create well formatted Form element with Form helper but without creation of form itself. So i wrote:
$this->Form->input(
'Kid.id',
array(
'type' => 'text',
)
);
This is ajax inside "Kids" controller response, and I'd like to update form after user make some actions.
I have no idea how to do it, except manually write HTML code.
Shame on me. This works I just forgot to add an echo at the beginning of line.

CakePHP: Field label in model

Are there any approaches to set in model field label? I dont want use 'label' property in form helper.
Please make sure I understand this correctly, you want to set a field label in the model, rather than using the form helper?
That violates basic MVC architecture. While Cake is flexible on some things, I don't think this is a possible option. I also don't see why you'd want to do it -- is there some reason that you don't want to use the label property in the form helper?
The basic issue is that the label for a form is part of the presentation layer, while the model represents the data. As such, it isn't possible (and I can't think of a situation where it'd make sense...) to assign a label to a data field which would then be used whenever that field is output.
If I misunderstood your question, please clarify.
What I do is setting up a convention in my models. I added a public attribute called "fieldLabels" to all the models, to assign default text labels for generic forms.
Example:
class MyModel extends AppModel {
// ...
public $fieldLabels = array(
'username' => 'User name',
'email' => 'e-mail address',
'phone' => 'Phone No.',
);
// ....
}
Then I pass around the labels to the view and use the extra parameter for the input, as sibidiba said:
echo $this->Form->input('title', array(
'label' => $fieldLabels['title'] . ': ',
));
In case I need special labels, I'll handle each case as an exception. Of course, if you want internationalization, that's a whole different topic.
Do you want to set the label's value? This is done in the view, but of course the value can originate from the controller/model. Like this:
echo $this->Form->input('title', array(
'label' => $titleLabel,
));
you can also disable the label element:
echo $this->Form->input('title', array(
'label' => null,
));
Not 100% sure, but I think you might be looking for Model::displayField
i suggest u directly use the helper u want.. bcos $form-input() creates div .. labels..
i personally had to weed out this on each line
with the direct helper like
$form->text()
$form->textarea()
$form->select()
u can keep the code much cleaner.
Note: $form->input saves time when used right...

Resources