El módulo se llama usersonline y pretende ser un campo que detecte si un usuario está o no logeado (esto lo pongo como curiosidad, ya que ese código aún no lo tengo creado, pero con que me detecte el nuevo campo me conformo por ahora).
Estructura del módulo (para simplificar la cosa, he metido todos los archivos en el root de módulo, aunque normalmente lo ordeno en una carpeta includes/views etc etc..).
usuersonline.info
Código:
usuersonline.modulename = Users online description = Determine if a user is or not online. core = 7.x dependencies[] = views ; Views files[] = views_handler_usersonline_field.inc
Código:
usersonline.views.inc/** * Implements hook_views_api(). */ function usersonline_views_api() { return array( 'api' => 3, ); }
Código:
views_handler_usersonline_field.inc/** * Implements hook_views_data(). */ function usersonline_views_data() { $data['usersonline']['table']['group'] = t('usersonline'); $data['usersonline']['table']['join'] = array( // #global is a special flag which let's a table appear all the time. '#global' => array(), ); $data['usersonline']['is_user_online'] = array( 'title' => t('is user online'), 'help' => t('Determine if a user is or not online".'), 'field' => array( 'handler' => 'views_handler_usersonline_field', ), // 'group' => 'usersonline', ); return $data; }
Código:
class views_handler_usersonline_field extends views_handler_field { /** * {@inheritdoc} * * Perform any database or cache data retrieval here. In this example there is * none. */ function query() { } /** * {@inheritdoc} * * Modify any end user views settings here. Debug $options to view the field * settings you can change. */ function option_definition() { $options = parent::option_definition(); return $options; } /** * {@inheritdoc} * * Make changes to the field settings form seen by the end user when adding * your field. */ function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); } /** * Render callback handler. * * Return the markup that will appear in the rendered field. */ function render($values) { return t('Some custom markup'); } }