当前位置: 首页>>代码示例>>PHP>>正文


PHP File::Create方法代码示例

本文整理汇总了PHP中Drupal\file\Entity\File::Create方法的典型用法代码示例。如果您正苦于以下问题:PHP File::Create方法的具体用法?PHP File::Create怎么用?PHP File::Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\file\Entity\File的用法示例。


在下文中一共展示了File::Create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: extractFormValues

 /**
  * {@inheritdoc}
  */
 public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state)
 {
     $field_name = $this->fieldDefinition->getName();
     // Extract the values from $form_state->getValues().
     $path = array_merge($form['#parents'], array($field_name));
     $key_exists = NULL;
     $values = NestedArray::getValue($form_state->getValues(), $path, $key_exists);
     if ($key_exists) {
         // Account for drag-and-drop reordering if needed.
         if (!$this->handlesMultipleValues()) {
             // Remove the 'value' of the 'add more' button.
             unset($values['add_more']);
             // The original delta, before drag-and-drop reordering, is needed to
             // route errors to the correct form element.
             foreach ($values as $delta => &$value) {
                 $value['_original_delta'] = $delta;
             }
             usort($values, function ($a, $b) {
                 return SortArray::sortByKeyInt($a, $b, '_weight');
             });
         }
         // Let the widget massage the submitted values.
         foreach ($values as $delta => &$value) {
             if (!empty($value['value']) && empty($value['fids'])) {
                 // ready to save the file
                 $provider_manager = \Drupal::service('video.provider_manager');
                 $allowed_providers = $this->getSetting('allowed_providers');
                 $enabled_providers = $provider_manager->loadDefinitionsFromOptionList($allowed_providers);
                 if ($provider_matches = $provider_manager->loadApplicableDefinitionMatches($enabled_providers, $value['value'])) {
                     $definition = $provider_matches['definition'];
                     $matches = $provider_matches['matches'];
                     $uri = $definition['stream_wrapper'] . '://' . $matches['id'];
                     $storage = \Drupal::entityManager()->getStorage('file');
                     $results = $storage->getQuery()->condition('uri', $uri)->execute();
                     if (!(count($results) > 0)) {
                         $user = \Drupal::currentUser();
                         $file = File::Create(['uri' => $uri, 'filemime' => $definition['mimetype'], 'filesize' => 1, 'uid' => $user->id()]);
                         $file->save();
                         unset($values[$delta]);
                         $values[] = array('fids' => array($file->id()), 'data' => serialize($matches));
                     } else {
                         unset($values[$delta]);
                         $values[] = array('fids' => array(reset($results)), 'data' => serialize($matches));
                     }
                 }
             }
         }
         $values = $this->massageFormValues($values, $form, $form_state);
         // Assign the values and remove the empty ones.
         $items->setValue($values);
         $items->filterEmptyItems();
         // Put delta mapping in $form_state, so that flagErrors() can use it.
         $field_state = static::getWidgetState($form['#parents'], $field_name, $form_state);
         foreach ($items as $delta => $item) {
             $field_state['original_deltas'][$delta] = isset($item->_original_delta) ? $item->_original_delta : $delta;
             unset($item->_original_delta, $item->_weight);
         }
         static::setWidgetState($form['#parents'], $field_name, $form_state, $field_state);
     }
 }
开发者ID:kallehauge,项目名称:iamkallehauge.com,代码行数:63,代码来源:VideoEmbedWidget.php


注:本文中的Drupal\file\Entity\File::Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。