Creating override and modifyng Article Button plugin

For Joomla! 4.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
User avatar
Nidzo2203
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 246
Joined: Sat Nov 21, 2009 4:52 pm
Contact:

Creating override and modifyng Article Button plugin

Post by Nidzo2203 » Sat Aug 06, 2022 5:13 pm

I want to add a css class to link from Article button so I can modify it. Probably wrapping link with div or span but I don't know how to do this. I appreciated your help.

I guess this is part of code that generates link in article.

Code: Select all

$link = 'index.php?option=com_content&view=articles&layout=modal&tmpl=component&'
			. Session::getFormToken() . '=1&editor=' . $name;
This is entire Article.php (plugins/editors-xtd/article/article.php)

Code: Select all

<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  Editors-xtd.article
 *
 * @copyright   (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\Session;

/**
 * Editor Article button
 *
 * @since  1.5
 */
class PlgButtonArticle extends CMSPlugin
{
	/**
	 * Load the language file on instantiation.
	 *
	 * @var    boolean
	 * @since  3.1
	 */
	protected $autoloadLanguage = true;

	/**
	 * Display the button
	 *
	 * @param   string  $name  The name of the button to add
	 *
	 * @return  CMSObject|void  The button options as CMSObject, void if ACL check fails.
	 *
	 * @since   1.5
	 */
	public function onDisplay($name)
	{
		$user  = Factory::getUser();

		// Can create in any category (component permission) or at least in one category
		$canCreateRecords = $user->authorise('core.create', 'com_content')
			|| count($user->getAuthorisedCategories('com_content', 'core.create')) > 0;

		// Instead of checking edit on all records, we can use **same** check as the form editing view
		$values = (array) Factory::getApplication()->getUserState('com_content.edit.article.id');
		$isEditingRecords = count($values);

		// This ACL check is probably a double-check (form view already performed checks)
		$hasAccess = $canCreateRecords || $isEditingRecords;
		if (!$hasAccess)
		{
			return;
		}

		$link = 'index.php?option=com_content&amp;view=articles&amp;layout=modal&amp;tmpl=component&amp;'
			. Session::getFormToken() . '=1&amp;editor=' . $name;

		$button = new CMSObject;
		$button->modal   = true;
		$button->link    = $link;
		$button->text    = Text::_('PLG_ARTICLE_BUTTON_ARTICLE');
		$button->name    = $this->_type . '_' . $this->_name;
		$button->icon    = 'file-add';
		$button->iconSVG = '<svg viewBox="0 0 32 32" width="24" height="24"><path d="M28 24v-4h-4v4h-4v4h4v4h4v-4h4v-4zM2 2h18v6h6v10h2v-10l-8-'
								. '8h-20v32h18v-2h-16z"></path></svg>';
		$button->options = [
			'height'     => '300px',
			'width'      => '800px',
			'bodyHeight' => '70',
			'modalWidth' => '80',
		];

		return $button;
	}
}

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 41878
Joined: Sat Apr 05, 2008 9:58 pm

Re: Creating override and modifyng Article Button plugin

Post by Webdongle » Sat Aug 06, 2022 6:19 pm

Why?
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

User avatar
Nidzo2203
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 246
Joined: Sat Nov 21, 2009 4:52 pm
Contact:

Re: Creating override and modifyng Article Button plugin

Post by Nidzo2203 » Sat Aug 06, 2022 8:26 pm

I want to achieve this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vel turpis at turpis molestie ullamcorper. Nulla eget luctus lacus.
(some font awesome icon) READ ALSO: THIS IS LINK INSERTED WITH ARTICLE BUTTON
In facilisis lacus eu ex porta eleifend. Duis blandit diam lorem, viverra condimentum magna facilisis ac. Aenean facilisis augue eu risus bibendum, eget imperdiet enim blandit.

I know I can add that manually but it is time consuming.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 29265
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Creating override and modifyng Article Button plugin

Post by Per Yngve Berg » Sat Aug 06, 2022 8:38 pm

You can do that with the JCE Editor. You can select articles with the Link Button on the toolbar

User avatar
Nidzo2203
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 246
Joined: Sat Nov 21, 2009 4:52 pm
Contact:

Re: Creating override and modifyng Article Button plugin

Post by Nidzo2203 » Sun Aug 07, 2022 4:47 pm

@Per Yngve Berg thanks for the hint. I created class but how to automatically add text like READ ALSO between font awesome icon and link?

I want to make it so simpler for website editors which often must add several related articles in current article in that way.

There is Article Thumbnail button plugin that I used on Joomla 3 site but it doesn't work on Joomla 4. I have contacted author but no answer. It's based on mentioned Article button just added possibility for showing thumbnails that I don't use.
That is why I asked for customizing Article button plugin. It's just 2 mouse clicks job for editor.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 29265
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Creating override and modifyng Article Button plugin

Post by Per Yngve Berg » Sun Aug 07, 2022 6:13 pm

Can you use the ::before to insert the text?

https://www.w3schools.com/Css/css_pseudo_elements.asp

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 41878
Joined: Sat Apr 05, 2008 9:58 pm

Re: Creating override and modifyng Article Button plugin

Post by Webdongle » Sun Aug 07, 2022 7:31 pm

http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".


Post Reply

Return to “Joomla! 4.x Coding”