예제 #1
0
 public function unpack_bundle()
 {
     $entity_bundle_array = field_info_bundles();
     $i = 1;
     foreach ($entity_bundle_array as $entity => $bundle_array) {
         foreach ($bundle_array as $bundle => $value_array) {
             // $this->temp_output[$entity][$bundle] = $i;
             $result[$bundle] = $entity;
             $i++;
         }
     }
     $this->entity = $result[$this->bundle];
     $this->bundle_array = $result;
     $supported = array_keys($result);
     if (!in_array($this->bundle, $supported)) {
         $this->output_message = "\"{$this->bundle}\" is NOT a supported bundle.";
         $this->output_message_type = __FUNCTION__ . ': ' . basename(__FILE__) . ' - line ' . __LINE__;
     }
     return;
 }
 protected function createInstance()
 {
     $entities = entity_get_info();
     $entityList = array_keys($entities);
     $entity = $this->dialog->select($this->output, 'What entity? ', $entityList);
     $entity = $entityList[$entity];
     $bundles = field_info_bundles($entity);
     $bundleList = array_keys($bundles);
     $bundle = $this->dialog->select($this->output, 'What bundle? ', $bundleList);
     $bundle = $bundleList[$bundle];
     $field_types = FieldBuilder::getFields();
     $fieldList = array();
     foreach ($field_types as $field => $definition) {
         $fieldList[$field] = sprintf("%s (%s)", $definition['label'], $field);
     }
     $fieldValues = array_keys($field_types);
     $field = $this->dialog->select($this->output, 'Field To Attach', array_values($fieldList));
     $field = $fieldValues[$field];
     $widget_types = WidgetBuilder::getTypesForFieldType($field_types[$field]['type']);
     $widgetList = array_keys($widget_types);
     $widget = $this->dialog->select($this->output, 'Widget to Use', array_values($widget_types));
     $widget = $widgetList[$widget];
     $label = $this->dialog->ask($this->output, 'What label for this instance? ');
     $widgetDefinition = new WidgetBuilder($widget, $label);
     $builder = new InstanceBuilder($field, $label, $widgetDefinition);
     $builder->build($entity, $bundle);
     $this->output->writeln("Created instance of field {$field} with label <info>{$label}</info> on {$entity}:{$bundle}");
     $this->mainQuestion();
 }