Using the group module in D8, I have the below view with machine name: group_members_per_group
Machine Name of:
- (Member account) User: Full Name is:
field_user_full_name
- (Member account) User: Phone Number is:
field_user_phone_number
The above view has the below results:
On cron run, and while Looping through all rows of the view results, I want to get for each
row the field_user_phone_number
value so I can use it with other code.
So I wrote:
function my_module_cron() {// Get and loop through the View `group_members_per_group`//$args = [$gid];$view = \Drupal\views\Views::getView('group_members_per_group');//$view->setArguments($args);$view->setDisplay('default');$view->execute();// Get the results of the view.$view_result = $view->result;// Check if the view is not empty and return results.if (!empty($view_result)) {// If the view returns results...foreach ($view->result as $row) {// Get the full name value.$name = $row->field_user_full_name;// check the result output for testing only.\Drupal::messenger()->addMessage(t($name)); } }}
However, on cron run, I am receiving the below error:
Notice: Undefined property: Drupal\views\ResultRow::$field_user_full_name in my_module_cron() (line 103 of modules\custom\my_module\my_module.module). my_module_cron(Object) call_user_func('my_module_cron', Object) (Line: 316) Drupal\ultimate_cron\Entity\CronJob->invokeCallback() (Line: 459) Drupal\ultimate_cron\Entity\CronJob->run(Object) (Line: 24) Drupal\ultimate_cron\Controller\JobController->runCronJob(Object) call_user_func_array(Array, Array) (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 582)……
Line 103 in the error is:
$name = $row->field_user_full_name;