joomla 1.7 : override a module helper.php - php

I want to override a helper.php file of a module, exactly
\administrator\modules\mod_quickicon\helper.php
what I want is to update the getButtons function in this file
what are the options I have to override this particular file ? its possible using a plugin ?
thanks

You can really only do a template override on the file in the tmpl folder called default.php. If you want to override helper.php, you're essentially rewriting the module itself. This isn't necessarily a bad thing, just copy the contents of the existing helper.php file into another file for backup, and hack away. The downside of doing this is that if someone updates the module, and you install that update, you'll have to redo your hack. Again, it's not that hard to work around. Just backup backup backup.
Some more thoughts:
You could also do the following:
1) Copy the module to a different folder, beginning with mod_ as well, but with a different name.
2) Modify the xml file, helper file, component file (and any others that are necessary) to account for the new name. Also do whatever you want to helper.php.
3) Go to extension manager and do a discover install of this new module
4) Go to module manager and make a new instance of the new module (using the same position as the old one).
5) Unpublish the module you're replacing
Doing this will keep you safe from update loss.

Here is what I've done with Joomla! 3.3.1 but it might be done with Joomla! 1.7, too:
Copy default.php from
/administrator/modules/mod_quickicon/tmpl/
to
/administrator/templates/YOUR_ADMIN_TEMPLATE_NAME/html/mod_quickicon/
Open the copied file and replace the line below
$html = JHtml::_('links.linksgroups', ModQuickIconHelper::groupButtons($buttons));
with these lines:
$myLinks = array(
'YOUR_QUICKICON_GROUP_NAME' => array(
array(
'link' => JRoute::_('index.php?option=com_YOURCOMPONENT'),
'image' => 'stack',
'icon' => 'header/icon-48-article-add.png',
'text' => JText::_('YOUR_QUICKICON_ITEM_NAME'),
'access' => array('core.manage', 'com_YOURCOMPONENT'),
'group' => 'YOUR_QUICKICON_GROUP_NAME'
)
)
);
$array = ModQuickIconHelper::groupButtons($buttons);
$array = array_merge($myLinks, $array);
$html = JHtml::_('links.linksgroups', $array);
That's it. You can edit or create /administrator/language/overrides/en-GB.override.ini and add these lines:
YOUR_QUICKICON_GROUP_NAME="The Group"
YOUR_QUICKICON_ITEM_NAME="The Item"
Enjoy!

Related

TYPO3: Override $GLOBALS['TCA'] with a function

In my extension I use an tablename.php file inside the tca/override folder to override some stuff defined by another extension. I know I can do this:
$GLOBALS['TCA']['tablename']['columns']['anoption']['config']['minitems'] = 1;
But when the original file says:
... 'anoption''config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'anoption',
['maxitems' => 7,]
What will be the override syntax? I was trying something like:
$GLOBALS['TCA']['tablename']['columns']['anoption']['config']['anoption']['maxitems'] = 3;
But that doesn't work and I don't know what I have to insert after config since in the original file there is that getFileTCAConfig function.
Also I was wondering how I could debug "$GLOBALS['TCA']['tablename']['columns']['anoption']" to somehow see all the suboptions, since I did not find anything inside the mysql database, I couldn't read any config from the phpMyAdmin.
I appreciate all the help!
You can debug the final TCA in the TYPO3 backend through the Configuration module in the System section. Once you open that module you select $GLOBALS['TCA'] (Table configuration array) in the topmost function select box:

Drupal 8 custom module add php classes

I have created a custom Drupal 8 module that works as is with a custom block and block form to collect some info.
This is all good.
I also have a twig template that I want to render a twitter feed using a php feed class I bought. I just don't know how it integrate this into the module.
This is the setup for the class: http://austinbrunkhorst.com/demos/twitter-class/#setup
It contains two files:
ultimate.twitter.feed.php
and
tmhOAuth.php
Which is currently a require_once 'tmhOAuth.php'; in the head of ultimate.twitter.feed.php
According to the instruction I should be creating a php file that has this:
$options = array(
'screen_name' => 'FeedTestUser',
'consumer_key' => '...',
'consumer_secret' => '...',
'user_token' => '...',
'user_secret' => '...',
);
$twitter = new Twitter($options);
$twitter->PrintFeed();
Which I'm guessing is also a hurdle as twig files are not php
Any help with this is very much appreciated.
C
I would setup the class as a Service in your module. Your block will then implement that service and do the handling. You don't really want to use require_once() if you can avoid it, rather use Drupal constructs (in part so that if you reorganize things later Drupal will help find the files in their new location).
Place the class in your module's src directory, and add a namespace to the start of the file (assuming there isn't one there already). Then in your block's class file you should be able to add a use statement that references that name space (even better would be to use a dependency injection, but the details on that would get in your way here).
In your block class's build() method you then instantiate the class as described in your question, but instead of just letting the module print HTML, you can want to capture that HTML and place it into your block as markup. If the class allows you to do that without using a buffer, you should (but I didn't see anything in the docs to support that), and then attempt to theme the structured data. If not, you can use PHP's output buffering to capture its attempt to print:
ob_start();
$twitter->PrintFeed();
$content= ob_get_contents();
ob_end_clean();
Then place the generated markup into a render array:
return [
'my_twitter_block' => [
'#markup' => $content,
],
];
Create a custom block and add the result of PrintFeed() to the render array. Just as with any usual custom block. In the render array you can specify a template which should be used (if needed). If you wanna output pure html without any template you could use the '#markup' key.
Small example:
Your block render array:
return array(
'#theme' => 'name_of_your_theme',
'#some_twig_variable' => $twitter->PrintFeed();
);
your your_module.module file (in the root of your module folder):
function your_module_theme() {
return array(
'name_of_your_theme' => array(
'variables' => array(
'some_twig_variable' => some-default-value,
),
),
);
}
your name-of-your-theme.html.twig template (should be under your_module/templates):
{{ some_twig_variable }}
As far as using the class: I see no problem using a require_once for that matter (in your Block php file). Of course it's always better/nicer if you can require the library/package via the make file or composer and then use the autoloader, but if that's not possible just put it e.g. in your drupal root under /libraries/twitter or so and then require it. If you do it like that you have to check that library into your git repository obviously.
have you use ultimate.twitter.feed.php in your TwitterBlock.php file
If not then try adding this line before class block beginns:
require_once 'path/to/twitter_class/ultimate.twitter.feed.php';

How to add autoload-function to CodeIgniter?

I would like to be able to use OOP and create new objects in my controllers in CodeIgniter. So I need to use an autoload-function:
function __autoload( $classname )
{
require_once("../records/$classname.php");
}
But how can I add that to CodeIgniter?
You can add your auto loader above to app/config/config.php. I've used a similar autoload function before in this location and it's worked quite neatly.
function __autoload($class)
{
if (strpos($class, 'CI_') !== 0)
{
#include_once(APPPATH . 'core/' . $class . EXT);
}
}
Courtesy of Phil Sturgeon. This way may be more portable. core would probably be records for you; but check your paths are correct regardless. This method also prevents any interference with loading CI_ libs (accidentally)
the User guide about Auto-loading Resources is pretty cleat about it.
To autoload resources, open the application/config/autoload.php file and add the item you want loaded to the autoload array. You'll find instructions in that file corresponding to each type of item.
I would suggest using hooks in order to add this function to your code.
Enable hooks in your config/config.php
$config['enable_hooks'] = TRUE;
In your application/config/hooks.php add new hook on the "pre_system" call, which happens in core/CodeIgniter.php before the whole system runs.
$hook['pre_system'] = array(
0 => array(
'function' => 'load_initial_functions',
'filename' => 'your_hooks.php',
'filepath' => 'hooks'
)
);
Then in the hooks folder create 2 files:
First: application/hooks/your_functions.php and place your __autoload function and all other functions that you want available at this point.
Second: application/hooks/your_hooks.php and place this code:
function load_initial_functions()
{
require_once(APPPATH.'hooks/your_functions.php');
}
This will make all of your functions defined in your_functions.php available everywhere in your code.

Order include file depending on inherit

Hi there people and greetings from Sweden!
I have a really tricky problem here. I'll try to show exactly what I mean.
I'm building a modulebased CMS, and some modules inherit from a parent module. My problem is that the parent modules need to be included before the "children".
I fetch moduleinfo from a XML file and store it in an array like this:
Array
(
[bloggy] => Array
(
[module_id] => blog
[module_name] => Blog
[module_desc] => Description
[module_url] => http://www.url.se
[author] => Dev Name
[author_url] => http://url.se
[version] => 1.0
[inherit] => core|twitter
[path] => /path/to/file
[dependon] => Array
(
[0] => core
[1] => twitter
)
)
I've done a explode on inherit and saved it into "dependon" as you see above. The problem now is, how can I sort which order to include the files. Every module inherits from core but if there is another module in the depenon array then the "child" module must be included after.
I hope you understand what I mean?
// Tobias
Look up "topological sort".
You could build you modules as classes and then use the __autoload magic function to automatically include/require all needed php files.
That way it's much less of a headache when you have complex dependencies.
Refer to the PHP manual for details on autoloading.
Just include all dependencies in your files. Try
// module1.php
require_once 'core.php'
// module2.php
require_once 'core.php'
require_once 'module1.php'
// module3.php
require_once 'core.php'
require_once 'module1.php'
require_once 'module2.php'
Including module3 will also include module2, module1 and core. You could leave out the core and module1 in module 3 and it would still load them all, but then you have to know what includes which.
Or use autoloading and don't bother about it.
Hmm I'll try to explain a little better.
I search the module folder for the xml info file and save the data into an array, I also save the path to the file in the array.
Then I use a foreach loop to include and instantiate the modules. My problem is that the parent modules must be instantiated before the "children".
I do not want to touch the core files when adding a new module, I need to use the hooks on a parent module.

Zend Framework Models not loading by autoloader

I've setup my application with Zend_Application. I have an _initAutoload() method in my Bootstrap.php wich looks like this:
public function _initAutoload(){
$this->bootstrap("frontController");
$front = $this->frontController;
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Client_');
$autoloader->registerNamespace('Frontend_');
$autoloader->registerNamespace('Global_');
$autoloader->registerNamespace('Global_Helper_');
$autoloader->setFallbackAutoloader(true);
$modules = $front->getControllerDirectory();
$default = $front->getDefaultModule();
foreach (array_keys($modules) as $module) {
if ($module === $default) {
continue;
}
$autoloader->pushAutoloader(new Zend_Application_Module_Autoloader(array(
"namespace" => ucwords($module),
"basePath" => $front->getModuleDirectory($module),
)));
}
return $autoloader;
}
I have setup FrontController to prefix the default module also (seems more logical to me) $front->setParam("prefixDefaultModule", true)
I think I have the usual directory structure.
The problem:
I've set up subdomains for every module that I have. Everything works fine in the main main domain (www). The main module is frontend. If frontend is the default module then stuff works :). Ok. Now. For every subdomain, I have the same index.php but theres changed the env value. For client subdomain the env value is client etc. Each env value corresponds to my application.xml section. Each application.xml subdomain section (client, api, etc) extend the main section which is called defaults (currently theres a testing section also which enables errors etc, so every subdomain extends testing and testing extends defaults).
Each subdomain section of the application.xml changes the default module name. So for section defaults its frontend, for section client its client, etc.
Now
When I access domain.com/client or domain.com/api - its fine. Both API & Client use Client_Model_NameOfTheModel and like it supposed to - it's located application/modules/client/models/NameOfTheModel.php and the DbTable/NameOfTheModel.php
WORKS
BUT
When I access the the module from its respective subdomain (client.domain.com, api.domain.com, etc) and the default module has been changed from frontend to its respective subdomain module name - it ends working. It even doesn't output that "stack trace".
Warning: include(Client/Model/ContactLists.php) [function.include]: failed to open stream: No such file or directory in [heres-my-path-to-root]/library/Zend/Loader.php on line 136
Warning: include() [function.include]: Failed opening 'Client/Model/ContactLists.php' for inclusion (include_path='[heres-my-path-to-root]/library:.:/usr/lib/php:/usr/local/lib/php') in [heres-my-path-to-root]/library/Zend/Loader.php on line 136
Fatal error: Class 'Client_Model_ContactLists' not found in [heres-my-path-to-root]/application/modules/client/controllers/ContactListsController.php on line 4
I've tried 2 days to get it working. It just doesn't. It just works under the default domain and doesn't when the application.xml changes its default module to its subdomain name. Like that. This point is very very crucial currently because I can't continue and this app needs to be out of sandbox (in early beta) by the end of this week.
Thanks for anyone for some advice.
PS. Sorry for the poor English. It isn't my native tongue
This is just a cursory guess, but it looks like it might be working on default because of these lines:
$autoloader->setFallbackAutoloader(true);
$modules = $front->getControllerDirectory();
$default = $front->getDefaultModule();
foreach (array_keys($modules) as $module) {
if ($module === $default) {
continue;
}
Essentially, if your module is the default module it skips it, which means it falls back to the fallback autoloader i would assume, and if the default autoloader cant find your models, well theres the issue. Is the concat of the root path in the error and the path of the class its trying to load correct?
Also, this looks like it might be wrong
"namespace" => ucwords($module),
I would think it would need to be
"namespace" => ucwords($module) . "_",
Like your other namespaces.
Which version of ZF are you using?
Are you using a later 1.8 - 1.10 version?
If so, you should be using the resource in Zend_Application for a module. It sets up autoloading for forms, models, helpers, etc under your modules.
If you are using an application.ini you should have a line like this for each module :
resources.modules.module_name = "enabled"
http://framework.zend.com/manual/en/zend.application.available-resources.html#zend.application.available-resources.modules

Categories