In my Silverstripe module I use $managed_models to create tabs on the right top, see here:
My code:
private static $managed_models = array(
'HomeRental',
'City',
'HomeType'
);
How can I translate the name of this tabs? I use the Silverstripe-translate module as well.
Thanks in advance!
This is done by translating the model's $singular_name value.
In your /module/lang/de.yml e.g.:
de:
GalleryPic:
PLURALNAME: Galeriebilder
SINGULARNAME: Galeriebild #translated singularname
db_Copyright: Copyright
has_one_Attachment: Anhang
You can even translate $db and $has_one fieldnames by prefixing the fieldname with db_ and has_one_ has_many_ and many_many_
Zauberfisch's BetterI18N module will help you whith an improved I18NTextcollectorTask that will collect all values for you and generates a yml file with all standard variables you need to translate your code.
IMHO it's useful to use english values in the code and templates directly (even if you develop in another language), grab all values with the TextcollectorTask and translate the yml files.
Related
I am trying to migrate files into a custom filetype with a lot of custom defined fields. However they seem to be getting migrated in the document filetype rather than into my custom created filetype.
I'm using the MigrateDestinationFile as my destination like this:
$this->destination = new MigrateDestinationFile();
I've tried to map the type like this answer suggested like this:
$this->addFieldMapping('type')->defaultValue('custom_file_type');
This solution doesn't work, when checking the mappable fields for the MigrateDestinationFile there is no type field specified so I think this is the reason why that solution doesn't work.
If some one could point me to an example of how to migrate into a custom file type that would be highly appreciated. Maybe I'm using the wrong destination? Or did I miss something very obvious.
The other part of the migration doesn't matter for this question.
Apparently I had two issues. The first one being that when we created the file type we called it file which for some reason you can't set as a migrate destination since it's already default in the MigrateDestinationFile constructor (see code below).
From file.inc:544
/**
* Basic initialization
*
* #param array $options
* Options applied to files.
*/
public function __construct($bundle = 'file', $file_class = 'MigrateFileUri', $options = array()) {
parent::__construct('file', $bundle, $options);
$this->fileClass = $file_class;
}
Second issue was the mapping to the field bundle itself. I simply had to set the correct destination like this after re-creating the file type with a different name:
$this->destination = new MigrateDestinationFile('product_download');
After doing this the migrated files where created in the correct content type rather than the document file type.
I am trying to learn how to use Drupal, and until i've been doing fine on my own. however there is one module that's teasing me - the Field Placeholder module.
basically what it does, it adds a placeholder entry to a field widget. per standard these widgets are text, number and mail modules. My problem is i can't figure out how i should extend the number of activated widgets, more specifically i want to add a placeholder attribute to the link module (https://drupal.org/project/link)
It says i can add other widgets via the hook_field_placeholder_info(), but how does that work? The documentation for this module is very limited, so please help a noob :)
Modules that provide an API, in this case defines hook_field_placeholder_info, usually have these functions defined in their .api.php file. For the field_placeholder module, that would be the field_placeholder.api.php file.
In there, you'll find:
/**
* Define field placeholder supported widgets.
*
* #return
* An array whose keys are the widget names and whose value are the widget
* item where the placeholder will be attached.
*/
function hook_field_placeholder_info() {
return array(
'text_textfield' => 'value',
'number' => 'value',
'email_textfield' => 'email',
);
}
From this, it looks like you need to implement this hook in your fork of the link module that returns an array something along the lines of:
function link_placeholder_info() {
return array(
'link_field' => 'value',
);
}
Granted, I haven't looked in the link module to see what the actual values are, but that should get you going. It might be a good idea to take a look at the text, number, and email modules to see how those values in the example line up with the actual values in their respective modules too.
I need to create a new custom formatter(using the module custom formatter) to replace some template code. So, for some fields, When I add a new custom formatter(field type: text) I need to print the title and the body. I tried to use $node->title but it doesn't work...
How can I do this? Probably using elements? And if yes...how?
Thanks in advance,
Regards,
Michele
Field formatters relate to the field that they are used for, it it's impossible to answer your question without know what field you are using (and it's contents).
To debug this, you could use the devel module and a bit of code. If you in your formatter write.
dpm(get_defined_vars());
this will give you a pretty printed list of all variables you have available. That should help you inspect and figure out how you get to what you need.
Custom formatters get's passed $element, if you do a dpm of $element (dpm($element) - If you have the Devel module installed) you will see the entire array, and notive that the $node object is passed as $element['#node'].
So with that said, to get to the node title you would use $element['#node']->title.
Please also not that it does say this on the help text of the custom formatters UI.
I'm using the module "simplenews" and during the registration process it reads "Select the newsletter(s) to which you wish to subscribe.".
I'd like to change this line and wanted to ask what the best way is to do so without hard coding it?
Thanks in advance!
I've also done this with the custom english version just so I could override a few strings. It works and is easier than hook_form_alter, but it also creates a bit of unnecessary overhead, especially if your site is otherwise not localized/multilingual.
There is nowadays a light and easy solution, that uses the same locale system, but you don't need to setup a custom english language or code anything: the "String Overrides"-module.
http://drupalmodules.com/module/string-overrides
Surprisingly, it's one of the top rated modules, out of over 5000 module.
Since it's located in a form, an easy and quick solution would be to change it with hook_form_alter.
Another solution would be to create your own custom version of the language english in Drupal and then "translate" the string into something different.
You could also skip the translation part, and use your settings.php file. You can create some custom string override in it without enableling the locale module. From the default.settings.php file:
/**
* String overrides:
*
* To override specific strings on your site with or without enabling locale
* module, add an entry to this list. This functionality allows you to change
* a small number of your site's default English language interface strings.
*
* Remove the leading hash signs to enable.
*/
# $conf['locale_custom_strings_en'] = array(
# 'forum' => 'Discussion board',
# '#count min' => '#count minutes',
# );
Or you can use String Overrides. Some more details about this module (from its project page):
Provides a quick and easy way to replace any text on the site.
Features
Easily replace anything that's passed through t()
Locale support, allowing you to override strings in any language
Ability to import/export *.po files, for easy migration from the Locale module
Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.
I'm in the progress of creating a bulk upload function for a Drupal site. Using flash I'm able to upload the files to a specific url that then handles the files. What I want to do, is not just to upload the files, but create a node of a specific type with the file saved to a filefield that has been setup with CCK. Since these are audio files, it's important that filefield handles the files, so addition meta data can be provided with the getid3 module.
Now I've looked through some of the code as I wasn't able to find an API documentation, but it's not clear at all how I should handle this. Ideally I could just pass the file to a function and just use the data returned when saving the node, but I haven't been able to find that function.
If any one has experience with this I would apreciate some pointers on how to approach this matter.
I had to do something similar some weeks ago and ended up adapting some functionality from the Remote File module, especially the remote_file_cck_attach_file() function. It uses the field_file_save_file() function from the filefield module, which might be the function you're looking for.
In my case, the files are fetched from several remote locations and stored temporarily using file_save_data(). Attaching them to a CCK filefield happens on hook_nodeapi() presave, using the following:
public static function attachAsCCKField(&$node, $filepath, $fieldname, $index=0) {
// Grab the filefield definition
$field = content_fields($fieldname, $node->type);
$validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field));
$fieldFileDirectory = filefield_widget_file_path($field);
// This path does not necessarily exist already, so make sure it is available
self::verifyPath($fieldFileDirectory);
$file = field_file_save_file($filepath, $validators, $fieldFileDirectory);
// Is the CCK field array already available in the node object?
if (!is_array($node->$fieldname)) {
// No, add a stub
$node->$fieldname=array();
}
$node->{$fieldname}[$index] = $file;
}
$filepath is the path to the file that should be attached, $fieldname is the internal name of the filefield instance to use within the node and $index would be the 0 based index of the attached file in case of multiple field entries.
The function ended up within a utility class, hence the class syntax for the verifyPath() call. The call just ensures that the target directory is available:
public static function verifyPath($path) {
if (!file_check_directory($path, FILE_CREATE_DIRECTORY)) {
throw new RuntimeException('The path "' . $path . '" is not valid (not creatable, not writeable?).');
}
}
That did it for me - everything else happens on node saving automatically.
I have not used the getid3 module yet, so I have no idea if it would play along with this way of doing it. Also, I had no need to add additional information/attributes to the filefield, so maybe you'd have to put some more information into the field array than just the file returned by field_file_save_file(). Anyways, hope this helps and good luck.
I have done something whith imagefield which worked, I think the structure has to be right otherwise it won't work. It took a lot of trial and error. This is is what I populated the imagefield with.
$image['data'] =array(
'title' => $media_reference_attributes->getNamedItem("source")->value,
'description' => $description,
'alt' => "",);
$image['width'] = $width;
$image['height'] = $height;
$image['mimetype'] = $mime_type
$image['uid'] = 1;
$image['status'] = 1;
$image['fid'] = $fid;
$image['filesize'] = $file->filesize;
$image['nid'] = $id;
$image['filename'] = $url;
$image['timestamp'] = $file->timestamp;
$image['filepath'] = $file_path;
Hope this is of some help.
You might want to look at Image FUpload if you need a look at integrating the flash upload.
To push the files on to another server while still handling them through Drupal sounds a little like the CDN space, maybe look at the behavior in the CDN or CDN2 projects?
If you find a clear solution please come back and post it!