Joomla package: How to enable plugin by default? - joomla

I have created a package in Joomla 3 that includes a module and a plugin. It installs both the module and plugin correctly but the plugin is disabled by default. Is there a way to make the plugin enabled by default- perhaps in the xml manifest of the package? I am unable to figure this out.

As #lodder already mentioned you can write your install script like
public function install ($parent)
{
$query = "update `#__extensions` set enabled=1 where type = 'plugin' and element = 'your-extension'";
$db = JFactory::getDBO();
$db->setQuery($query);
$db->query();
// Probably you want to enable the module on all pages too
$query = "insert into `#__modules_menu` (menuid, moduleid) select 0 as menuid, id as moduleid from `#__modules` where module like 'mod_my-awesome-menu%'";
$db->setQuery($query);
$db->query();
}
You can find my working example here https://github.com/Digital-Peak/DPAttachments/blob/master/com_dpattachments/script.php#L15

I think the best way would be to run a sql statement after installation that get the plugin by ID and change its status from 0 to 1

Related

How to get disabled entities in TYPO3 8.x extbase?

I've set up a simple repository query setting to get certain fe_user in TYPO3 CMS 8.7.22. Without disable this fe_user the repository gives back the expected entity.
But after disable the object again the repository returns null. So why setIgnoreEnableFields and setEnableFieldsToBeIgnored doesn't work anymore?
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$defaultQuerySettings = $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
$defaultQuerySettings->setRespectSysLanguage(FALSE);
$defaultQuerySettings->setRespectStoragePage(TRUE);
$defaultQuerySettings->setIgnoreEnableFields(TRUE);
$defaultQuerySettings->setEnableFieldsToBeIgnored(array('disable'));
$someRepository->setDefaultQuerySettings($defaultQuerySettings);
$response = $someRepository->findByIdentifier($fe_user_id);
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($response);
It is the findByUid function from the default frontendUserRepsository. There they prevent to get hidden / deleted objects. So I build my own repository function for that case:
public function findHiddenByUid($uid){
$query = $this->createQuery();
$qs = clone($this->defaultQuerySettings);
$qs->setIgnoreEnableFields(TRUE);
$qs->setEnableFieldsToBeIgnored(['disable','hidden','disabled']);
$query->setQuerySettings($qs);
$query->matching($query->equals('uid', $uid));
return $query->execute()->getFirst();
}

How to get the list of attributes on frontend in Magento 2

I'm using Magento 2, when I try add product in Backend, in the Configurations tab, I have created Configuration and I saw there three attributes.
How can I get them in a module on frontend?
I see they are stored in eav_attribute table but I dont know which SQL can be do it, because it has no conditional column
Thank so much!
Use can use below code to get attribute in your module frontend.
$attribute = $objectManager->create('\Magento\Eav\Model\Config')->getAttribute('catalog_product', 'color');
$colorAttributeId= $attribute->getAttributeId();
foreach ($attribute->getSource()->getAllOptions(true) as $option) {
$colors[$option['value']] = strtolower($option['label']);
}
print_r($colors);

how to call a plugin after user login in joomla 3.0

I am trying to auto create jomsocial albums using a plugin after adding the jomsocial library in plugin in the event function onUserLogin. onUserLogin if i am trying to fetch the $my = JFactory::getUser(); is returs null value. SO the jomsocial library also act same with user values.
Can't be sure without any of you code to look at, but the Joomla user plugin uses this when it starts:
public function onUserLogin($user, $options = array())
{
$instance = $this->_getUser($user, $options);

joomla override model for mod_banners

I'm using Joomla 3.1 and I'm using template hacks to override mod_banners -
/mytemplate/html/mod_banners/default.php
Which is working fine.
However, the banners module calls the file:
/components/com_banners/models/banners.php
Which I can't seem to override. I've tried moving the file (and folders) into my /mytemplate/html folder, but that doesn't work.
I've also tried putting the following code into my banners default.php file:
JModelLegacy::addIncludePath(JPATH_ROOT.'/templates/home/com_banners/models/', 'BannersModel');
$model = JModelLegacy::getInstance('Banners', 'BannersModel', array('ignore_request' => true));
$banners = $model->getItems();
But that doesn't work either. Is there any way I can override the query in /com_banners/models/banners.php without changing the core files?
All I'm trying to do is to pull in the descriptions for each banner, without changing the core.
Thanks in advance!
The only way to override a model in Joomla is to make your own version of the original, and load (register) it through a system plugin, before the model is accessed for the first time. For your use case, that is way too complicated.
Even if it is not good practice, since it breaks up the MVC structure, I'd fetch the data from within the template.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id, name, description')
->from('#__banners');
$db->setQuery($query);
$banners = $db->loadObjectList();
Now you can access all banner descriptions, fx. in a loop:
foreach ($banners as $banner) {
echo $banner->id, ': ', $banner->description;
}

How to Get Global Article Parameters in Joomla?

I'm programming a module in Joomla! 2.5. The module displays an article at a given position.
I need article attributes (i.e. show_title, link_title ecc.)
With this code I get article's specific attributes:
$db =& JFactory::getDBO();
$query = 'SELECT * FROM #__content WHERE id='.$id.' AND state=1';
$db->setQuery($query);
$item = $db->loadObject();
$attribs = json_decode($item->attribs, true);
If i var_dump the $attribs variable I get:
array(26) {
["show_title"]=>
string(0) ""
["link_titles"]=>
string(0) ""
[...]
}
The variable $attribs represents the article's specific attributes. When an element is set to "" means "use the global configuration".
I can get the global configuration with this query:
SELECT params from #__extensions where extension_id=22;
Where 22 is the id of the com_component extension. Then I can merge the results here with the results for the specific article.
BUT is there an easy way to achieve this? Does Joomla! have a specific class in the framework for this?
I would start with loading the model for articles:
// Get an instance of the generic articles model
$model = JModel::getInstance('Article',
'ContentModel',
array('ignore_request' => true));
The get the specific article...
$model->getItem($id)
To get a components global params I believe you can use:
$params = &JComponentHelper::getParams( 'COMPONENT_NAME' );
In your case you would need something like:
jimport('joomla.application.component.helper'); // load component helper first
$params = JComponentHelper::getParams('com_content');
I would suggest you look at the code of the article modules that ship with Joomla! 2.5.x as they do a lot of similar things to what you're trying to create. You can also have a read of this article, it's a bit dated but I think it still mostly holds true (except for jparams being replaced by jforms).

Resources