/** * Called by ModuleCodeFile to collect functions from its child components. */ public function componentFunctions() { // Get the function data from our parent class first. $return = parent::componentFunctions(); // If we were requested without any permissions, just return template code. if (empty($this->component_data['permissions'])) { return $return; } // Otherwise, replace the template code with the permissions. // TODO: this is the same pattern as the HookMenu generator: generalize // this in a single class? $code = array(); // Opening lines. // DX sugar: use £ for variables in the template code. $code[] = "£permissions = array();"; $code[] = ""; foreach ($this->component_data['permissions'] as $permission_name) { $code[] = "£permissions['{$permission_name}'] = array("; $code[] = " 'title' => t('TODO: enter permission title'),"; $code[] = " 'description' => t('TODO: enter permission description'),"; $code[] = ");"; } $code[] = "return £permissions;"; $return[$this->name]['code'] = $code; // We return an array of lines, so we need newlines at start and finish. $return[$this->name]['has_wrapping_newlines'] = FALSE; return $return; }
/** * Called by ModuleCodeFile to collect functions from its child components. */ public function componentFunctions() { // Get the function data from our parent class first. $return = parent::componentFunctions(); // If we were requested without any menu items to make (ie via the Hooks // component rather than RouterItem), just return template code. if (empty($this->component_data['menu_items'])) { return $return; } // Otherwise, replace the template code with the menu items. $code = array(); // Opening lines. // DX sugar: use £ for variables in the template code. $code[] = "£items = array();"; $code[] = ""; foreach ($this->component_data['menu_items'] as $menu_item_data) { // Add defaults for each menu item. $menu_item_data += array('title' => 'My Page', 'page callback' => 'example_page', 'access arguments' => "array('access content')", 'type' => 'MENU_SUGGESTED_ITEM'); $code[] = "£items['{$menu_item_data['path']}'] = array("; $code[] = " 'title' => '{$menu_item_data['title']}',"; $code[] = " 'page callback' => '{$menu_item_data['page callback']}',"; // This is an array, so not quoted. $code[] = " 'page arguments' => {$menu_item_data['page arguments']},"; // This is an array, so not quoted. $code[] = " 'access arguments' => {$menu_item_data['access arguments']},"; // The type is a constant, so is not quoted. $code[] = " 'type' => {$menu_item_data['type']},"; $code[] = ");"; } $code[] = "return £items;"; $return[$this->name]['code'] = $code; // We return an array of lines, so we need newlines at start and finish. $return[$this->name]['has_wrapping_newlines'] = FALSE; return $return; }