0

When I try to access protected property in feed object I am getting error (Error: Cannot access protected property Drupal\feeds\State::$messages)

Feed Object:

enter image description here

Anybody know How to get protected property(messages) from object?

  • How about $yourObject->getMessages(); – batMask Jan 16 at 7:29
  • @batMask I tried below methods, but not working. $msg_obj = $event->getFeed()->getState(StateInterface::PROCESS); $msg_obj->messages(); $msg_obj->getMessages(); $msg_obj->displayMessages(); – Ram Jan 17 at 5:48
1

There is no public method on the State object that returns the messages. The public methods on the object are:

  • progress()
  • setCompleted()
  • setMessage()
  • displayMessages()
  • logMessages()

The method displayMessages() is the closest method you can use to access the messages, the messages are then transferred to \Drupal\Core\Messenger\Messenger, which has a method called all() to return all the messages on that object.

PHP also has an API called 'Reflection', which - among more - allows you to bypass visibility settings on class properties and methods. The main purpose for this API is to retrieve doc comments for functions, classes and methods. I wouldn't recommend to use this unless if it is for debug purposes.

Note that since Feeds 8.x-3.0-alpha6 the messages are also displayed on the feed page while an import is not yet completed.

Why do you need access to the messages? Maybe you can open a feature request ticket in the Feeds issue queue to request adding a public method for retrieving the messages.

  • In D8, we don't have any feed error log page to see what errors are coming up in feed failed with some errors in importing. For that I am trying to create feed logs page based on these error messages. My plan was based on these error messages in state object and store it in new table and display it in error log page. – Ram Jan 28 at 6:32
  • @Ram If it isn't a problem that you record these errors after the import is completed, you can also create your own logger service in a custom module. This way, you can catch the log messages created by Feeds and store them the way you want. Check the core dblog and syslog modules for example implementations. Feeds passes the feed entity as additional context. This is ignored by dblog and syslog, but your custom module could use it to link the message with the feed entity. – MegaChriz Jan 29 at 10:06
  • Thanks for your valuable inputs. I will differently try this custom logger service way. – Ram Jan 29 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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