lucid-fox / social-magick

An Open Graph Image generator plugin for Joomla 3 and 4
GNU General Public License v3.0
15 stars 1 forks source link

Possibility to manually Select an Image for Menu Items and for Categories #35

Closed woluweb closed 2 years ago

woluweb commented 2 years ago

What is the use case of your proposed feature? SocialMagick works fine on Article pages. But when I wanted to select an image for

I even looked at the Category, but there also we only see those 4 options

Describe the solution you'd like After chatting on Messenger with Crystal to confirm that I had not missed some obvious option, she confirmed that it was not possible with the current version. So I suggested the following, which seems to me to be quite universal (would work of any type of Menu Item and also on Categories) : simply add a 5th option being "select file"

Note: Crystal was wondering about Menu Cascading. Actually, this is another topic. If we can already set manually each level of Menu Item, we are fine. I am not asking for Cascading

Why do you think this is relevant to people other than you? Well, Blog views (or Featured) is quite typical on websites, especially for the homepage (and elsewhere of course). So it is a bit paradoxical that we would have an og:image for the Articles but not for the rest of the site With other words, the plugin would be more universal. It is a common usecase.

woluweb commented 2 years ago

Besides I was wondering: in a Menu Item for example the Option Generate Open Graph images gives two choices

woluweb commented 2 years ago

Txs! Exciting times :)

woluweb commented 2 years ago

Txs a lot for 1.0.2! Tested successfully :)

It works perfectly for all Types of Menu Items. There is just one side-effect that I had not anticipated. Above I had said that cascading was not important (in the sense of a submenu inheriting the configuration of its parent). I still stick to that.

The main goal of having "static image" for Blog View was to be able to have an og:image for the Blog View as well, not only for the corresponding Articles. But here I realize that

The ideal would be to have the best of both worlds

PS: besides this it seems that the package still refers to 1.0.1 so the extensions update manager keeps thinking that the update has not been done

nikosdion commented 2 years ago

Yes, that is the only possible way this can work. Otherwise you'd have to override each and every article. Remember the menu item ID in a category view is always the same no matter if you are viewing the list of items or each individual item.

As I have already explained in our documentation we are not going to add features which require knowing how each extensions works for the simple reason that you can create template overrides, as Crystal already told you on Messenger.

In this case, you'd assign the SocialMagick template for the articles to the menu item. In your category list / blog view template override you can override the SocialMagick template so that the blog view page and only that page uses that different template:

\Joomla\CMS\Menu\AbstractMenu::getInstance()->getActive()->getParams()->set('socialmagick.template', 'A Different Template Here');

You can of course override specific parameters instead of assigning a different template as per the link above.

woluweb commented 2 years ago

Txs for the clarification @nikosdion!

You understand SocialMagick (and Joomla in general and coding :D ) much better than I do :)

So am I summarizing it correctly that

  1. in the Menu Item of Type Blog, I can leave the setting of the SocialMagick on "full image" so that all the Single Article View will take that parameter automatically
  2. but in my override of the Blog View, I should add the line of code you are quoting so that the Blog View can have a Static Image ?

If so, I understand the idea and it is indeed easy to implement.

But still in practice I am not sure of what the following line should then become in my Blog View override :) \Joomla\CMS\Menu\AbstractMenu::getInstance()->getActive()->getParams()->set('socialmagick.template', 'A Different Template Here');

(and actually, to improve on that idea, I suppose I could actually add that line of code in a Module Override, so that I could assign that Module to all Menu Items of Type "Blog", with the same common image)

nikosdion commented 2 years ago

1 & 2. Yes.

A Different Template Here is the name of a different SocialMagick template. You are in control of that name, I can't give you that.

About module overrides. Modules are loaded per active menu item therefore in article sub-pages as well. This is the same problem you are trying to solve. That's a whole lot of work to achieve... nothing?

woluweb commented 2 years ago

1 & 2. Yes.

Good :)

A Different Template Here is the name of a different SocialMagick template. You are in control of that name, I can't give you that.

OK, I think I get what you meant. The Template is like "Overlay" or "Solid". With other words, the code would be \Joomla\CMS\Menu\AbstractMenu::getInstance()->getActive()->getParams()->set('socialmagick.template', 'Solid'); If I put that in an override of /components/com_content/tmpl/category/blog.php then I get the following error msg Too few arguments to function Joomla\CMS\Menu\AbstractMenu::getInstance(), 0 passed in /home/festivalki/dev/components/com_content/tmpl/category/blog.php on line 18 and at least 1 expected

Anyways, now I undertand that this line allows to force another Template in the sense of "Solid", "Overlay", ... But all I wanted to do was to force a static image for the Blog View (keeping the default Overlay Template). So I guess the line(s) of code should be slightly different but I have no clue :)

(I apologize if this sounds too obvious for you, but I am just trying to find my way :) )

About module overrides. Modules are loaded per active menu item therefore in article sub-pages as well. This is the same problem you are trying to solve. That's a whole lot of work to achieve... nothing? Oopsie, that's right :) (unless I restrict the override to the blog view in the PHP of course, which is one line of code)

PS: FYI it is still <version>1.0.1</version> in the xml file. (I corrected it manually on my own sites)