コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getRequiredFields()
 {
     $field = new Field();
     $field->setLabel('Title');
     $field->setMachine('title');
     $field->setType('Node module element');
     $field->setWidgetNameVisible(false);
     return array('Title' => $field);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function getRequiredFields()
 {
     $fieldName = new Field();
     $fieldName->setLabel('Name');
     $fieldName->setMachine('name');
     $fieldName->setType('Term name textfield');
     $fieldName->setWidgetNameVisible(false);
     $fieldDescription = new Field();
     $fieldDescription->setLabel('Description');
     $fieldDescription->setMachine('description');
     $fieldDescription->setType('Term description textarea');
     $fieldDescription->setWidgetNameVisible(false);
     return array('Name' => $fieldName, 'Description' => $fieldDescription);
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function getRequiredFields()
 {
     $fileNameField = new Field();
     $fileNameField->setLabel('File name');
     $fileNameField->setMachine('filename');
     $fileNameField->setType('File name');
     $fileNameField->setWidgetNameVisible(false);
     $filePreviewField = new Field();
     $filePreviewField->setLabel('File');
     $filePreviewField->setMachine('preview');
     $filePreviewField->setType('File preview');
     $filePreviewField->setWidgetNameVisible(false);
     return array('File name' => $fileNameField, 'File' => $filePreviewField);
 }
コード例 #4
0
 /**
  * Work out if a particular field value is considered "special" (and further processing is required).
  *
  * If it's special, process it into its proper value.
  *
  * @param mixed $value
  *   The special command used to populate this field's value.
  *
  * @return mixed
  *   The processed value. For example, if random text was requested, returns random text instead of the value that
  *   requests random text.
  */
 public static function parseSpecialValue($value)
 {
     // If array, recurse values.
     if (is_array($value)) {
         $output = array();
         foreach ($value as $key => $innerValue) {
             $output[$key] = Field::parseSpecialValue($innerValue);
         }
         return $output;
     }
     // If we're not dealing with a special value we can just bail out immediately at this point.
     if (substr($value, 0, 9) != 'special::') {
         return $value;
     }
     $special = substr($value, 9);
     switch ($special) {
         case 'randomText':
         default:
             $value = static::randomText();
             break;
     }
     return $value;
 }
 /**
  * {@inheritdoc}
  */
 public function loadGlobalExtras()
 {
     // Make sure to initialise by reading the data source.
     if (!$this->isInitialised()) {
         $this->parseDataSource();
     }
     $globalExtras = array();
     if (empty($this->config)) {
         throw new ConfigurationException("Configuration file is invalid");
     }
     if (isset($this->config['GlobalExtras'])) {
         foreach ($this->config['GlobalExtras'] as $extraData) {
             $extra = Field::parseYaml($extraData);
             $globalExtras[$extra->getMachine()] = $extra;
         }
     }
     return $globalExtras;
 }
コード例 #6
0
 /**
  * Construct a ContentType by parsing yaml configuration.
  *
  * @param array $yaml
  *   Yaml in a standard format as found in contentTypes.yml.
  * @param array $fields
  *   Yaml for the global fields in a standard format as found in contentTypes.yml.
  * @param array $extras
  *   Yaml for the global extras in a standard format as found in contentTypes.yml.
  *
  * @return ContentType
  *   A fully populated ContentType object.
  */
 public static function parseYaml($yaml, $fields = array(), $extras = array())
 {
     $contentType = new ContentType();
     $contentType->setHumanName($yaml['humanName']);
     $contentType->setMachineName($yaml['machineName']);
     // Set the entity type.
     if (isset($yaml['entityType'])) {
         $contentType->setEntityType($yaml['entityType']);
     } else {
         // Use node as our default if no entity type is set.
         $contentType->setEntityType('node');
     }
     // Set all the required fields for this content type.
     foreach ($contentType->getEntityType()->getRequiredFields() as $field) {
         $contentType->setField($field);
     }
     // Set all fields on this content type as defined in the yaml.
     if (isset($yaml['fields'])) {
         foreach ($yaml['fields'] as $key => $fieldData) {
             // The 'globals' key is the old way of writing it instead of 'globalFields' which is maintained for
             // backwards compatibility.
             if ($key == 'globals' || $key == 'globalFields') {
                 // Handle the list of global fields specially.
                 $fields = Field::parseGlobalFields($fieldData, $fields);
                 $contentType->setFields($fields);
             } else {
                 // Handle a single field definition.
                 $field = Field::parseYaml($fieldData, $fields);
                 $contentType->setField($field);
             }
         }
     }
     // Set all extras on this content type as defined in the yaml.
     if (isset($yaml['extras'])) {
         foreach ($yaml['extras'] as $key => $extraData) {
             if ($key == 'globalExtras') {
                 // Handle the list of global extras specially.
                 $extras = Field::parseGlobalFields($extraData, $extras);
                 $contentType->setExtras($extras);
             } else {
                 $extra = Field::parseYaml($extraData);
                 $contentType->setExtra($extra);
             }
         }
     }
     if (isset($yaml['submit'])) {
         $contentType->setSubmitSelector($yaml['submit']);
     }
     return $contentType;
 }