I built a simple module to find the files in a folder and display them. However no "content" is rendered and I get warnings from a core-include file. Here is the module file:
<?php
function composer_example_menu() {
$items = array();
$items['composerExample/composer_example'] = array(
'title' => 'Composer Demo',
'page callback' => 'get_current_files', // 'call_back_function_name',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* A utility function to return the array of current SplFileInfo objects
*/
function get_current_files()
{
require __DIR__.'/../../../../../vendor/autoload.php';
// the "files" directory
$dir = drupal_realpath(file_default_scheme() . '://');
$finder = new \Symfony\Component\Finder\Finder();
$finder->in($dir)
->name('*.txt')
;
$files = array();
foreach ($finder as $file) {
$files[] = $file->getFilename();
}
return $files;
The Warnings I get:
Warning: Invalid argument supplied for foreach() in element_children() (line 6583 of /Applications/MAMP/htdocs/drupal-7.51/includes/common.inc). Warning: Illegal string offset '#children' in drupal_render() (line 6040 of /Applications/MAMP/htdocs/drupal-7.51/includes/common.inc). Warning: Illegal string offset '#children' in drupal_render() (line 6050 of /Applications/MAMP/htdocs/drupal-7.51/includes/common.inc). Warning: Illegal string offset '#children' in drupal_render() (line 6088 of /Applications/MAMP/htdocs/drupal-7.51/includes/common.inc). Warning: Illegal string offset '#printed' in drupal_render() (line 6095 of /Applications/MAMP/htdocs/drupal-7.51/includes/common.inc).