/**
  * Define the response Html for field.
  *
  * @param $name string
  * @param $value integer
  * @param $default integer/string
  * @param $attr array
  * 
  * @return string
  */
 public function getHtml($name, $value = null, $default, array $attr = null)
 {
     // $attr['class'] = "form-control";
     $nameE = '';
     $format = "{!! Form::hidden('%s',  1) !!}";
     if (substr($name, -3) == '_id') {
         $nameE = explode("_", $name);
         $nameE = $nameE[0];
         $format = "{!! Form::hidden('%s',  Auth::%s()->id, %s) !!}";
     }
     // echo Form::hidden('email', '*****@*****.**');
     return sprintf($format, $name, $nameE, FieldHelper::arrayToString($attr));
 }
 /**
  * Define the response Html for field.
  *
  * @param $name string
  * @param $value integer
  * @param $default integer/string
  * @param $attr array
  * 
  * @return string
  */
 public function getHtml($name, $value = null, $default, array $attr = null)
 {
     $attr['class'] = "form-control";
     $format = "{!! Form::text('%s', null, %s) !!}";
     return sprintf($format, $name, FieldHelper::arrayToString($attr));
 }
 public static function changeInstanceField(array $instance, $new_field_name)
 {
     $old_field = field_info_field($instance['field_name']);
     $new_field = field_info_field($new_field_name);
     if ($old_field['type'] != $new_field['type']) {
         throw new FieldException("Cannot change field instance because they are not the same field type.");
     }
     if ($old_field['storage']['type'] !== 'field_sql_storage') {
         throw new FieldException("Unable to change field type for field {$old_field['field_name']} using storage {$old_field['storage']['type']}.");
     }
     if ($new_field['storage']['type'] !== 'field_sql_storage') {
         throw new FieldException("Unable to change field type for field {$new_field['field_name']} using storage {$new_field['storage']['type']}.");
     }
     if (!field_info_instance($instance['entity_type'], $new_field_name, $instance['bundle'])) {
         $new_instance = $instance;
         $new_instance['field_name'] = $new_field_name;
         field_create_instance($new_instance);
         watchdog('helper', "Created new field instance: {$instance['entity_type']}.{$instance['bundle']}.{$new_field_name}");
     }
     // Copy data from old field tables to the new field tables.
     $old_data_table = _field_sql_storage_tablename($old_field);
     $new_data_table = _field_sql_storage_tablename($new_field);
     $query = db_select($old_data_table, 'old');
     $query->fields('old');
     $query->condition('entity_type', $instance['entity_type']);
     $query->condition('bundle', $instance['bundle']);
     db_insert($new_data_table)->from($query)->execute();
     $old_revision_table = _field_sql_storage_revision_tablename($old_field);
     if (db_table_exists($old_revision_table)) {
         $new_revision_table = _field_sql_storage_revision_tablename($new_field);
         $query = db_select($old_revision_table, 'old');
         $query->fields('old');
         $query->condition('entity_type', $instance['entity_type']);
         $query->condition('bundle', $instance['bundle']);
         db_insert($new_revision_table)->from($query)->execute();
     }
     FieldHelper::deleteInstance($instance);
 }
Example #4
0
 public static function getAllReferencesTo($entity_type, array $entity_ids, EntityFieldQuery $query = NULL, $flatten = FALSE)
 {
     if (!isset($query)) {
         $query = new EntityFieldQuery();
         $query->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
     }
     $references = array();
     $fields = FieldHelper::getEntityReferencingFieldsByType($entity_type);
     foreach ($fields as $field_name => $columns) {
         foreach (array_keys($columns) as $column) {
             $field_query = clone $query;
             $field_query->fieldCondition($field_name, $column, $entity_ids);
             if ($results = $field_query->execute()) {
                 if ($flatten) {
                     $references = drupal_array_merge_deep($references, $results);
                 } else {
                     $references[$field_name . ':' . $column] = $results;
                 }
             }
         }
     }
     return $references;
 }