SugarCRM - How to set the default homepage for all users - php

I am using SugarCRM Version 5.2.0k (Build 5837). I would like to be able to set a default home page (with dashlets I've created myself) that will be the same for all users, can anyone advice on best way to do this?
Thanks in advance for your help

I'd like to know how to do this too... see here for some ideas, but it's clear that it's not a supported feature.
I wonder if you can write a module that installs a hook for post user creation (assuming that this hook is provided) and then populate the appropriate part of the user preferences table when the hook is invoked. Of course, your module will probably break with each upgrade of SurgarCRM, so this might be more trouble than it i worth.
Edit:
I had a look at the Dash Manager module that is referenced in the thread I linked to above. It's approach is to copy the preferences of the admin user to all other users when the administrator clicks a link in the admin page. So, the admin user is used as a sort of template for other users. Rudimentary solution, but not a bad start - using a template user and treating the preferences (as stored in the DB table) as opaque seems like the way to go.

It's quite easy to do it.
I have done it in SugarCRM 6.5.23.
Here I have mentioned steps to do it:
Just copy sugarcrm_root/modules/Home/index.php and paste it in SugarCRM_root/custom/modules/Home/index.php.
Now you can customize it's behavior as you want.
You can remove default dashlets and add your own dashlets by creating one file at SugarCRM_root/custom/modules/Home/dashlets.php and add this code in it:
<?php
unset($defaultDashlets);
$defaultDashlets = array(
'CustomDashlet' => 'ModuleName',
'UpcomingAppointmentsDashlet' => 'Meetings', //Example
);
Once you do this thing still you have 3 dashlets left in your hook code you can remove it if it's needed code for that hook is like this:
$dashlets[create_guid()] = array(
'className' => 'iFrameDashlet',
'module' => 'Home',
'forceColumn' => 0,
'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
'options' => array('titleLabel' => 'LBL_DASHLET_DISCOVER_SUGAR_PRO',
'url' => '...',
'height' => 315,
));
Hope this will help you. :)

Related

How to create a Wordpress, Site-origin widget default or preset image value?

I am trying to build an stylable widget that loads with preset or default styling values when introduced to a page. I have been able to utilize default=”” within the form fields to achieve this effect on all buttons and text. But I am trying to establish a background image that will load in initially and allow the user to change the image through the provided fields. Is there a way to set a default image value in my field setting to achieve this functionality? I have provided my attempt below to better demonstrate my goal.
‘fields’ => [
‘image’ => [
‘type’ => ‘media’,
‘label’ => __(‘Image’, ‘widgets-bundle’),
‘choose’ => __(‘Choose image’, ‘widgets-bundle’),
‘update’ => __(‘Set image’, ‘widgets-bundle’),
‘default’ => ‘exampel.org/wp-
content/uploads/2021/05/randomimage_2560x890.jpg’,
‘library’ => ‘image’,
‘fallback’ => true,
],
...
]
Thank you!
Unfortunately, the Media Field doesn't currently support defaults at this time. Your best bet for doing this would be to either create a custom field that allows for this, or alter the base custom field using the siteorigin_widgets_field_registered_class_paths hook. That hook allows you to override the base form field main file with a file of your choosing so you can use it to introduce additional features or control defaults. The documentation for this filter is still pending, but you can find the current version here.

What are the possible ways to translate in MediaWiki from "backend", without an extension?

I have a MediaWiki 1.33.0 website with only one extension → ContactPage, with which I can have a simple contact form.
Using HTMLForms template engine (in which the default form-template for ContactPage is written), I have expanded the default form to include a selection menu.
My problem
Selection list array keys and values of this selection menu are written in English inside LocalSettings.php but my site isn't primarily in the LTR English, rather, it is in the RTL Hebrew and I would like them to appear in my site's native language for end users.
My own code pattern
wfLoadExtension( 'ContactPage' );
$wgContactConfig['default'] = array(
'RecipientUser' => 'Admin', // Must be the name of a valid account which also has a verified e-mail-address added to it.
'SenderName' => 'Contact Form on ' . $wgSitename, // "Contact Form on" needs to be translated
'SenderEmail' => null, // Defaults to $wgPasswordSender, may be changed as required
'RequireDetails' => true, // Either "true" or "false" as required
'IncludeIP' => false, // Either "true" or "false" as required
'MustBeLoggedIn' => false, // Check if the user is logged in before rendering the form
'AdditionalFields' => array(
'omgaselectbox' => [
'class' => 'HTMLSelectField',
'label' => 'Select an option',
'options' => [
'X' => 'X',
'Y' => 'Y',
'Z' => 'Z',
],
],
),
// Added in MW 1.26
'DisplayFormat' => 'table', // See HTMLForm documentation for available values.
'RLModules' => array(), // Resource loader modules to add to the form display page.
'RLStyleModules' => array(), // Resource loader CSS modules to add to the form display page.
);
possible solutions
1) Writing selection list array keys and values in Hebrew (which might be a bit messy due to LTR-RTL clashings):
'options' => [
'ס' => 'ס',
'ט' => 'ט',
'ז' => 'ז',
],
2) Translating English selection list array keys and values in client side JavaScript by some similar code:
document.getElementById('select').selectedIndex = 0;
document.getElementById('select').value = 'Default';
My desire
I desire an ordinal backend way to do so, and if there is one, than without an extension
In this discussion, a MediaWiki community member recommended using system message transclution but the chapter dealing with it was very unclear to me; I didn't understand what this is about and how can this help in my situation.
My question
What are the possible ways to translate in MediaWiki from "backend", without an extension?
The localisation system is working perfectly fine in the backend (php), as well in the frontend (JavaScript) parts of MediaWiki → staying with it backend is best as it is more minimal.
Assuming you take a backend only approach:
Translation with a predefined string
If your desired translations already exist in MediaWiki (e.g. on another page of form), you can "simply" re-use the key. So, let's assume, your current additional select field definition looks like this:
'Select' => [
'type' => 'select',
'options' => [
'The english message' => 'value'
]
],
Then, you would change it to something like this:
'Select' => [
'type' => 'select',
'options-messages' => [
'the-message-key' => 'test'
]
],
Please consider the changing of options into the options-messages key.
Also: Change the key the-message-key to the message key you want to reuse.
If you know a page where the message/string is used, you can just open that page with the GET option uselang and the value qqx, in order to see the message key. Example: If the string is used on the login page, simply open the login page with https://example.com/wiki/Special:Userlogin?uselang=qqx to show all the message keys used on the page.
However, one warning when doing that: It is mostly discouraged to re-use existing message keys, especially when they're used on other pages. The keys are translated to hundreds of languages with that specific context in mind. That could also mean, that a translation in a specific language does not fit when the string/message is used on the contact page. So I would suggest to use the second option below.
Translation without a predefined string
Usually it will be done by extension which can provide a specific directory where the JSON files with the message key translations are saved. However, as you're "just" customizing an extension, you need a way to put in the translations for your keys.
So, first of all, let's take over the changes from above. Change your select field definition to be something like:
'Select' => [
'type' => 'select',
'options-messages' => [
'my-fancy-key' => 'test'
]
],
Now, two ways to get the key translated:
On-Wiki
By saving the message on-wiki, the messages can also easily being changed simply by editing the respective page in the wiki. In our example, let's translate the key to english and hebrew:
English: Edit the page MediaWiki:My-fancy-key in your wiki and add the desired text.
Hebrew: Edit the page MediaWiki:My-fancy-key/he in your wiki and add the desired text.
As part of the deployed code
We need to register a directory with JSON files for the translations of these messages. We're using the same configuration variable as extensions would use as well, $wgMessagesDirs, even given that we don't create an extension. Add the following line to your LocalSettings.php:
$wgMessagesDirs['ContactPageCustomization'] = __DIR__ . '/customContactPage';
Now, create a directory customContactPage in the root folder of your MediaWiki installation and put in the following file with the following contents:
en.json
{
"my-fancy-key": "Default"
}
If you want to translate to another language, create a new file with the language code you want to translate to. In hebrew it should be he, so let's create a new language file:
he.json
{
"my-fancy-key": "ברירת מחדל"
}
If you then open the contact page, the message key my-fancy-key should be translated to the english Default and the same (at least based on Google Translate) for hebrew. This is a more stable way of adding custom translations, however, you now also need to take care of translating the keys into the languages you want to support on your own as well. If a key is not translated into the selected language of the user, the default language, english, is used.

How am I supposed to be using filter_xss? Even though I'm using it, coder gives me an issue

+269: [critical] Potential problem: drupal_set_message
http://api.drupal.org/api/function/drupal_set_message/() only accepts
filtered text, be sure all !placeholders for $variables in t
http://api.drupal.org/api/function/t/() are fully sanitized using
check_plain http://api.drupal.org/api/function/check_plain/(),
filter_xss http://api.drupal.org/api/function/filter_xss/() or
similar.
Which pertains to this code:
drupal_set_message(t('Batch complete! View/Download !results', array(
'!results' => filter_xss(l(t('simple results'), file_create_url($filename))),
)), 'info');
What's going wrong?
The method you're using is under the 'DO NOT DO THESE THINGS' portion of Dynamic or static links in translatable strings. You need to change it to one of the approved methods. For reference:
<?php
// DO NOT DO THESE THINGS
$BAD_EXTERNAL_LINK = t('Look at Drupal documentation at !handbook.', array('!handbook' => ''. t('the Drupal Handbooks') .''));
$ANOTHER_BAD_EXTERNAL_LINK = t('Look at Drupal documentation at the Drupal Handbooks.');
$BAD_INTERNAL_LINK = t('To get an overview of your administration options, go to !administer in the main menu.', array('!administer' => l(t('the Administer screen'), 'admin'));
// Do this instead.
$external_link = t('Look at Drupal documentation at the Drupal Handbooks.', array('#drupal-handbook' => 'http://drupal.org/handbooks'));
$internal_link = t('To get an overview of your administration options, go to the Administer screen in the main menu.', array('#administer-page' => url('admin')));
?>

Drupal 7 - why is my action not showing up in the triggers menu?

I've added a second element to the userbeep_action_info() hook which I plan to make into a new action, but when I check it in the Triggers page, it doesn't appear. The first item, userbeep_beep_action shows, but not the second. Why is this? Is it because it's configurable that it needs extra information to appear? My book asks me to check for its presence at this stage but it isn't appearing.
<?php
/**
* #file
* Writes to the log every time a user logs in or edits a node.
*/
/**
* Implementation of hook_action_info().
*/
function userbeep_action_info() {
return array(
'userbeep_beep_action' => array(
'type' => 'system',
'label' => t('Beep annoyingly'),
'configurable' => FALSE,
'triggers' => array('node_view', 'node_insert', 'node_update', 'node_delete')
),
'userbeep_multiple_beep_action' => array(
'type' => 'system',
'label' => t('Beep multiple times'),
'configurable' => TRUE,
'triggers' => array('node_view', 'node_insert', 'node_update', 'node_delete')
)
);
}
/**
* Simulate a beep. A Drupal action.
*/
function userbeep_beep_action() {
watchdog('beep', 'Beep! at ' . '');
}
From the Book's error corrections site - http://www.drupalbook.com/errata3
Error: The screenshot in Figure 3.4 is of the wrong overlay. (What is
shown in Figure 3.4 is not available until an instance of the advanced
action has been created as described on pp. 43-44 and in Figure 3.5.)
Correction: What should be shown in Figure 3.4 is the overlay
accessed by clicking the Configuration link in the top menu and then
clicking on the Actions link in the Configuration page, and finally
scrolling to the bottom of the overlay to the "Create an Advanced
Action" drop-down select box.
The figure you're basing your assumption that your code isn't working isn't the right one. Complete the rest of the chapter and you'll get it working. Use the resource above to hunt down more errors in the book.
Hint: There are quite a few...
It is not showing up because advanced (configurable) actions need to be created and configured once defined in code at: /admin/config/system/actions, where as simple actions do not. It may also require the configuration form and actions to be defined first as well.

Drupal - Automate a Content Form Submission

I would like to programatically (using php) fill out an existing drupal form to create a content type that is included in a contributed module.
Details: The module is SimpleFeed and the content type is Feed. I would like to call the module's functions to accomplish this. The method I am interested in is hook_insert which appears to require vid and nid which I am unsure what these are.
Any help is appreciated.
can you provide a bit more information (which modules?). generally, i'd probably suggest calling the modules functions to create the content type, instead of trying to pass it through a form programatically. this way you don't have to worry about implementation, and can trust that if the module works, it'll work for your script too :)
of course this does tie your module to theirs, so any changes in their functions could affect yours. (but then again, you run that risk if they update their database structure too)
ex.
// your file.php
function mymodule_do_stuff() {
cck_create_field('something'); // as an example, i doubt this
// is a real CCK function :)
}
edit: vid and nid are node ID's, vid is the revision id, and nid is the primary key of a particular node. because this is an actual node, you may have to do two operations.
programatically create a node
you'll have to reference the database for all the exact fields (tables node and node_revisions), but this should get you a basic working node:
$node = (object) array(
'nid' => '', // empty nid will force a new node to be created
'vid' => '',
'type' => 'simplefeed'. // or whatever this node is actually called
'title' => 'title of node',
'uid' => 1, // your user id
'status' => 1, // make it active
'body' => 'actual content',
'format' => 1,
// these next 3 fields are the simplefeed ones
'url' => 'simplefeed url',
'expires' => 'whatever value',
'refresh' => 'ditto',
);
node_save($node);
now i think it should automatically call simplefeed's hook_insert() at this point. if not, then go on to 2. but i'd check to see if it worked out already.
call it yourself!
simplefeed_insert($node);
edit2: drupal_execute() isn't a bad idea either, as you can get back some validation, but this way you don't have to deal with the forms API if you're not comfortable with it. i'm pretty sure node_save() invokes all hooks anyhow, so you should really only have to do step 1 under this method.
The drupal api provides drupal_execute() to do exactly this. I would suggest you avoid calling the functions directly to create the node (unless there is a performance reason). By using drupal_execute() all the proper hooks in other modules will be called and your code is far more likely to continue to work through future versions of drupal.
Note that a classic bug in using this method is not first calling something like
module_load_include('inc', 'node', 'node.pages')
which will load the code for your node creation form.
Calling node_save directly is generally considered deprecated and could leave you with broken code in future versions of drupal.
There is a nice example at this lullabot post

Categories