Joomla 3.0—get module id inside custom form - joomla3.0

I have created Joomla module and added a custom field type at the parameter configuration in the backend, using the .xml file like this:
<fields name="params">
<fieldset
addfieldpath="/modules/<module_name>/fields" name="basic">
<field name="articles" type="articles" label="label" />
.
.
.
</fields>
That is working pretty fine but there is on question left over: How can I access the module's id inside the custom field class, when invoked to create the fields html?
Thanks in ahead!
UPDATE
I digged a bit deeper in that found the JModuleHelper::getModule($type, $name) method, which returns either the first module of the given $type if no $name is specified, or the module of the given $type having the $name, but since it is possible to create Modules with the same name, this approach is kind of ugly.

The solution is hidden in the URL and in case of Joomla, in JInput. Complete and more verbose explanation is here (a the bottom), but in short:
URL of a modules edit screen:
index.php?option=com_modules&view=module&layout=edit&id=87
Would be too easy to just use this…

Related

Angular Schema Form HTML Attributes?

I've been looking over the Angular Schema Form documentation to be able to apply attributes to the elements generated at: https://github.com/Textalk/angular-schema-form/blob/development/docs/index.md
Have been looking up and down and have found nothing. I see through defining the schema that you can define custom HTML classes:
htmlClass: "street foobar", // CSS Class(es) to be added to the container div
fieldHtmlClass: "street" // CSS Class(es) to be added to field input (or similar)
labelHtmlClass: "street" // CSS Class(es) to be added to the label of the field (or similar)
But, haven't been able to find where I can apply attributes like the data attribute or an attribute specific to the element itself. Any resources in regards to this type of basic functionality you'd expect from form generation?
Any ideas?
Thanks!
I do not think this is possible to do purely through json schema definitions, you would have to extend Schema Form and provide your own HTML template with your custom attributes. I've had this problem myself and have had to do the very same.
I'm sure you've seen this but here's the docs on extending:
https://github.com/json-schema-form/angular-schema-form/blob/master/docs/extending.md

Append content of field to title field in Wagtail-CMS-admin

In order to differentiate pages in Wagtail CMS admin (in a page listing view, not in the edit page view), the title is - in my case - not enough. I have a long list of pages of one page-type (say class BlogPage), and some of these pages could have the same title. So I would like to add a second identifying field (here: date_from, a DateField) to this title.
I thought of
class BlogPage(Page):
...
def title(self):
if self.date_from:
return self.date_from + " - " + self.title
else:
return self.title
but this does not work, the page.title without my def is used for the corresponding Wagtail-admin-template.
Short version: How to pre/-append an existing field to the title in Wagtail-admin?
If you'd like to replace the title across all of the model admin (Yes, this includes the Edit page), Wagtail has a built in mechanism for that.
def get_admin_display_title(self):
return '{} - {}'.format(self.date_from, super().get_admin_display_title())
title is an actual Django model attribute, don't try to override it: https://docs.djangoproject.com/en/dev/topics/db/models/#field-name-hiding-is-not-permitted
The actual admin template from wagtailadmin/pages/list.html generates the list of pages in a loop using {% for page in pages %} and calls {{ page.title}} via an include (templates/wagtailadmin/pages/listing/_page_title_explore.html) extensively throughout. So based on inspecting the code, there is no support for this in Wagtail itself. Check the other includes templates/wagtailadmin/pages/listing/*.
However, Django supports overriding one app's templates with your own. You can copy this template into your project's template folder, keeping the same path (e.g., templates/wagtailadmin/pages/listing/_page_title_explore.html assuming your project is set up with a templates directory).
You'll have to replace the calls to page.title with your own version. A filter or tag might make this easier. Add the following filter to your templatetags (e.g. myapp/templatetetags/myapp_tags.py):
register = template.Library()
#register.filter
def uniquify_title(page):
specific_page = page.specific
try:
return specific_page.date_from.strftime("%Y-%m-%d") + " - " + specific_page.title
except AttributeError:
return specific_page.title
And then replace usages of {{ page.title}} in the template starting around line 7 and 9 with:
{{ page|uniquify_title }}
The downside of this is you have to update your own version of list.html every time Wagtail is updated. You could try submitting an issue on Github and proposing a fork which supplies an "admin_title" callable or something like that.
wagtailmodeladmin seems to do exactly what I've searched for: extending the wagtailadmin to display a defined set of fields - not only title - on a page model basis; like I would have it in the Django admin site.
This way I do not alter the default wagtailadmin page listing - like I've tried it in my question, but hook in an additional page listing as an extra wagtail-sidebar-navigation-entry.
Thanks to an other answer I stumbled upon this possiblity.

cakephp placeholder if image not exist

I have a database with images associated to each entry.
Anyhow, some entries don't have an image.
Googling I found some js and php way to apply in the view, but I'm pretty sure there is a (much nicer) MVC-way to do this, just I don't know how..
Is there a nice Cake-way to display placeholder image where none exist?
Supposed the data you set from the controller named 'post'. And you have 'your_default_image' in your /app/webroot/img/
<?php
if(empty($post['Post']['img'])) {
echo $this->Html->image($post['Post']['img']);
} else {
echo $this->Html->image('your_default_image');
}
And you can wrap those logic in your helper.
You can use placehold.it anywhere you need for placeholding images.
Just use http://placehold.it/WxH like http://placehold.it/250x250 and you're set.

Unable to add a new field to a content type, widget drop down not working

These are my first steps with drupal.
I have created a taxonomy hierarchy for my articles and now I am trying to add a new field to the content type "Article" and "Media" so the content admin can assign a "category" to his new content.
So I've been to Structure > Content Types > Article > Manage Fields
Then "Add new field" with :
1- Label = Category
2- Name = "field_category
3- Field = "Term reference"
**4- Automatically changes to "Select list" but I am unable to see the drop down list options. Clicking the list doesn't do anything, I couldn't select Autocomplete or any other value I've seen on forums & tutorials. Using firebug I could see the options are there, but the list doesn't show up.**
This is happening with all types of fields, even with text fields, the most basic one.
Any idea why is this happening ?
As glumbo mentioned, the problem here is caused by jQuery 1.7 update. As of jQuery 1.6 DOM properties should be accessed using .prop() function.
There is an open issue with some hotfix solution:
You need to replace .attr() jQuery function call with .prop() in /modules/field_ui/field_ui.js at following lines:
100: $(this).html(html).attr('disabled', disabled ? 'disabled' : '');
253: $(ajaxElements).attr('disabled', true);
Please note that this fix modifies a Drupal core module and you'll probably want to use a patch (Dries would kill the kitty anyway:).
The problem is with jquery update. If you are using jquery 1.7 you will get this problem

How to set form name and id using cakephp FormHelper class?

I'm trying to create a form using Cakephp's FormHelper class. The form needs to have a name and and an id. I fail to see an option for that however.
Looking at the documentation for the Formhelper, I see a lot of things, but not a way to set name and option. It's not in the source for the Formhelper either. How are these values set?
Cakephp v1.2 is the version of cake i'm running here
EDIT: the form is being submitted to an external destination. It is not a form associated with any model in the app.
You can simply pass any additional attributes in the $options parameter. If there's no special meaning for Cake (like url), it'll use it as HTML attributes:
echo $form->create('Model', array('id' => 'myId'));
<form id="myId" method="post" action="/models/add">

Resources