3

I have follow code for after save:

public function onContentAfterSave ($context, $article, $isNew)
{
$article = JModelLegacy::getInstance('Article', 'ContentModel')->getItem(); 
....
}

It works fine if I save an article.
But it will execute too if I save other things like a Weblink, so there comes the error measage:

Call to a member function getItem() on boolean

Now I'am look for a rule to check that the code only execute by save an article like

 public function onContentAfterSave ($context, $article, $isNew)
    {
    if (IS_A_ARTCLE) {  ... }
    }

1 Answer 1

3

You use the $context variable for that. So you have to start your function like this:

public function onContentAfterSave ($context, $article, $isNew)
{
  if ($context == "com_content.article") {
      // Your code for articles here
  }
}
1
  • Fantastc, THATS it. nexttime I will RTFM. 1000 Thanks
    – Lovntola
    Commented Jan 18, 2019 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.