Mercurial > hg > MPIWG-drupal-modules
view sites/all/modules/custom/mediathek/mediathek.module @ 0:015d06b10d37 default tip
initial
author | dwinter |
---|---|
date | Wed, 31 Jul 2013 13:49:13 +0200 |
parents | |
children |
line wrap: on
line source
<?php /** * Implementation of hook_enable(). */ function mediathek_enable() { #adds a field for the current collection // Check if our field is not already created. if (!field_info_field('field_mediathek_entry')) { $field = array( 'field_name' => 'field_mediathek_entry', 'type' => 'mediathek_mediathek_entry', ); field_create_field($field); // Create the instance on the bundle. $instance = array( 'field_name' => 'field_mediathek_entry', 'entity_type' => 'node', 'label' => 'Mediathek Entry', 'bundle' => 'node', // If you don't set the "required" property then the field wont be required by default. 'required' => False, 'settings' => array( ), 'widget' => array( 'type' => 'mediathek_default_mediathek_entry', ), ); field_create_instance($instance); } } /* implements a new field type for the medithek id */ function mediathek_field_info(){ return array('mediathek_mediathek_entry' => array ( 'label' => t('Mediathek Item'), 'description' => t('This field stores an mediathek Item'), 'settings' => array('max_length' =>20), 'instance_settings' => array('text_processing' => 0), 'default_widget' => 'mediathek_default_mediathek', 'default_formatter' => 'mediathek_mediaviewer', ), ); } function mediathek_field_is_empty($item, $field){ return empty($item['url']); } function mediathek_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { $field_name = $field['field_name']; $field_type = $field['type']; $url = isset($items[$delta]['url']) ? $items[$delta]['url'] : ''; $height = isset($items[$delta]['url']) ? $items[$delta]['height'] : ''; $width = isset($items[$delta]['url']) ? $items[$delta]['width'] : ''; $widget = $element; $widget['#delta'] = $delta; switch ($instance['widget']['type']) { case 'mediathek_default_mediathek': $fieldset_info = element_info('fieldset'); $process = array_merge($fieldset_info['#process'], array('mediathek_media_entry_process')); $widget+= array( '#type' => 'fieldset', '#title' => t('Contact settings'), '#weight' => 5, '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, '#process' => $process, ); $widget['url'] = array( '#title' => t('Url'), '#type' => 'textfield', '#default_value' => $url, '#size' => 150, '#maxlength' => 500, ); $widget['height'] = array( '#title' => t('Height'), '#type' => 'textfield', '#default_value' => $height, '#size' => 20, '#maxlength' => 20, ); $widget['width'] = array( '#title' => t('Width'), '#type' => 'textfield', '#default_value' => $width, '#size' => 20, '#maxlength' => 20, ); $element['media'] = $widget; break; } return $element; } function mediathek_media_entry_process(&$form, &$form_state, $complete){ array_pop($form['#parents']); return $form; } function mediathek_field_widget_info() { #TODO:both types should check if field is valid return array( 'mediathek_default_mediathek' => array( 'label' => t('Media Item'), 'field types' => array('mediathek_mediathek_entry'), ), ); } function mediathek_field_formatter_info() { return array( // This formatter shows the obejct with fullmetadata 'mediathek_mediaviewer' => array( 'label' => t('Mediathek viewer'), 'field types' => array('mediathek_mediathek_entry'), ) ); } function mediathek_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); switch ($display['type']) { // This formatter simply outputs the field as text and with a color. case 'mediathek_mediaviewer': foreach ($items as $delta => $item) { $url = $item['url']; $width = $item['width']; $height= $item['height']; if ($url!=""){ $element[$delta]['#markup'] = theme('mediathek_theme_mediathek_mediaviewer',array('item' => $item )); } } break; } return $element; } function mediathek_theme(){ return array( 'mediathek_theme_mediathek_mediaviewer' => array( 'variables' => array('item' => NULL), 'template' => 'mediathek-theme-mediathek-mediaviewer', ) ); }