Webylon 3.2 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • 1c
    • exchange
      • catalog
  • auth
  • Booking
  • building
    • company
  • cart
    • shipping
    • steppedcheckout
  • Catalog
    • monument
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • HTMLDropdownField
  • SimpleTreeDropdownField
 1 <?php
 2 
 3 /**
 4  * A {@link DropdownField} that allows HTML in its option tags
 5  * Overloads {@link DropdownField::Field()} to omit Convert::raw2xml
 6  * @package DataObjectManager
 7  */
 8  
 9 class HTMLDropdownField extends DropdownField
10 {
11     /**
12      * Returns a <select> tag containing all the appropriate <option> tags.
13      * Makes use of {@link FormField->createTag()} to generate the <select>
14      * tag and option elements inside is as the content of the <select>.
15      * 
16      * @return string HTML tag for this dropdown field
17      */
18     function Field() {
19         $options = '';
20 
21         $source = $this->getSource();
22         if($source) {
23             // For SQLMap sources, the empty string needs to be added specially
24             if(is_object($source) && $this->emptyString) {
25                 $options .= $this->createTag('option', array('value' => ''), $this->emptyString);
26             }
27             
28             foreach($source as $value => $title) {
29                 
30                 // Blank value of field and source (e.g. "" => "(Any)")
31                 if($value === '' && ($this->value === '' || $this->value === null)) {
32                     $selected = 'selected';
33                 } else {
34                     // Normal value from the source
35                     if($value) {
36                         $selected = ($value == $this->value) ? 'selected' : null;
37                     } else {
38                         // Do a type check comparison, we might have an array key of 0
39                         $selected = ($value === $this->value) ? 'selected' : null;
40                     }
41                     
42                     $this->isSelected = ($selected) ? true : false;
43                 }
44                 
45                 $options .= $this->createTag(
46                     'option',
47                     array(
48                         'selected' => $selected,
49                         'value' => $value
50                     ),
51                     $title
52                 );
53             }
54         }
55         
56         $attributes = array(
57             'class' => ($this->extraClass() ? $this->extraClass() : ''),
58             'id' => $this->id(),
59             'name' => $this->name,
60             'tabindex' => $this->getTabIndex()
61         );
62         
63         if($this->disabled) $attributes['disabled'] = 'disabled';
64 
65         return $this->createTag('select', $attributes, $options);
66     }
67 
68 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.2 API Docs API documentation generated by ApiGen 2.8.0