Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to set document head (meta) data #19234

Closed
wants to merge 9 commits into from
Closed

Add method to set document head (meta) data #19234

wants to merge 9 commits into from

Conversation

joomdonation
Copy link
Contributor

Pull Request for Issue # .

Summary of Changes

In view classes of a component, we usually have to set document head data like page title, description, meta keywords, meta description, robots...

Instead of writing that repeating code again and again in every view, this PR introduces a new method called setDocumentHeadDatas to do that work. Component view classes now only need to set necessary data to $params property of the view if needed and call setDocumentHeadDatas method to set these data for document

Testing Instructions

Code review for now. If the concept is accepted, I will convert actual view classes (like category view) to use this new method and human testing will be needed at that time.

}

if ($parent == false)
if ($category == false || $parent == false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it correct to be == here but === elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is from original code, I just merged two commands into one. If it is needed, I can change it later. The main thing I want to get feedback is whether this concept is accepted (and useful) or not before working to use it for our view classes (to reduce repeating code).

*
* @return void
*
* @since 3.9.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to __DEPLOY_VERSION__


$title = $params->get('page_title');

// Check for empty title and add site name if param is set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace lines 897-911 with setDocumentTitle method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is my intention to have these lines of code in the method. If this is accepted, we can set all these head data within single method, no need for using setDocumentTitle method anymore

*
* @since __DEPLOY_VERSION__
*/
protected function setDocumentHeadDatas()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data is considered singular/plural. Perhaps change it to setDocumentHeadData.

@ggppdk
Copy link
Contributor

ggppdk commented Jan 2, 2018

You can use method
public function setDocumentTitle($title)
#11399

exists inside same class, so your setDocumentHeadData() could make use of it

@joomdonation
Copy link
Contributor Author

Yes, I am aware of that method. I just think maybe we don't need that method in the future, so sometime it can be deprecated and can be removed from the class in the future

@ggppdk
Copy link
Contributor

ggppdk commented Jan 2, 2018

Reasoning for adding setDocumentTitle($title) is same as adding setDocumentHeadData()
i would argue to make use of it, and reduce the code size of setDocumentHeadData()

@ggppdk
Copy link
Contributor

ggppdk commented Jan 2, 2018

About removing it

  • someone would want to call setDocumentHeadData()
  • and then call setDocumentTitle($title) to override only the title

Also It is probably best to completly remove the "title" code from setDocumentHeadData()
and then you have 2 small methods to call inside views like this:

$this->setDocumentTitle();
$this->setDocumentHeadData();  // or maybe "setDocumentMeta()" or something

Thus you achieve both replacing the repeatable code,
and also making things easier in terms of overriding the default behavour,
more clean and more flexible

@joomdonation
Copy link
Contributor Author

I don't think it is good to call setDocumentHeadData and then call setDocumentTitle($title) to override only the title. If we do that, we would have the same code run two times, it is a waste of resource. It is better to call $this->params->set('page_title', $title) before calling setDocumentHeadData();

If we have a use case which we only need to set page title, not other meta data like description, robots..., on a View class, then Yes, we should keep setDocumentTitle and use it on setDocumentHeadData. Otherwise, I would like to keep the code as how it is at the moment.

@ggppdk
Copy link
Contributor

ggppdk commented Jan 2, 2018

yes, that s why i said that my 2nd suggestion is better,
it is best to have 2 methods with distinct functionality

@joomdonation
Copy link
Contributor Author

I still prefer one method call per view only. I don't like having to call two methods:

$this->setDocumentTitle();
$this->setDocumentHeadData(); 

Can we get feedback from PLT about this?

$this->document->setMetadata('robots', $params->get('robots'));
}

$metaData = $this->params->get('metadata');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where can I set this data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass it before calling this method. For your information, we are using it here https://github.com/joomla/joomla-cms/blob/staging/components/com_content/views/category/view.html.php#L250-L258

@mbabker
Copy link
Contributor

mbabker commented Jan 4, 2018

Can't say I'm a fan of this. It's introducing more undocumented class member variables into a base class we already have problems with having undocumented variables on. And it's making a hard reservation on the $params variable, both in terms of name and data type.

@joomdonation
Copy link
Contributor Author

@mbabker I change it to pass $params as method parameter. Hope it is OK now.

@brianteeman
Copy link
Contributor

@mbabker are the changes better now or are your comments still valid in which case this should be closed

@mbabker
Copy link
Contributor

mbabker commented May 8, 2018

Seems fine as is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants