When I try to access protected property in feed object I am getting error
(Error: Cannot access protected property Drupal\feeds\State::$messages)
Anybody know How to get protected property(messages) from object?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
There is no public method on the State object that returns the messages. The public methods on the object are:
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.