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


PHP FieldDefinitionInterface::getSetting方法代码示例

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


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

示例1: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $min = $field_definition->getSetting('min') ?: 0;
     $max = $field_definition->getSetting('max') ?: 999;
     $values['value'] = mt_rand($min, $max);
     return $values;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:IntegerItem.php

示例2: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $random = new Random();
     if ($field_definition->getItemDefinition()->getSetting('link_type') & LinkItemInterface::LINK_EXTERNAL) {
         // Set of possible top-level domains.
         $tlds = array('com', 'net', 'gov', 'org', 'edu', 'biz', 'info');
         // Set random length for the domain name.
         $domain_length = mt_rand(7, 15);
         switch ($field_definition->getSetting('title')) {
             case DRUPAL_DISABLED:
                 $values['title'] = '';
                 break;
             case DRUPAL_REQUIRED:
                 $values['title'] = $random->sentences(4);
                 break;
             case DRUPAL_OPTIONAL:
                 // In case of optional title, randomize its generation.
                 $values['title'] = mt_rand(0, 1) ? $random->sentences(4) : '';
                 break;
         }
         $values['uri'] = 'http://www.' . $random->word($domain_length) . '.' . $tlds[mt_rand(0, sizeof($tlds) - 1)];
     } else {
         $values['uri'] = 'base:' . $random->name(mt_rand(1, 64));
     }
     return $values;
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:29,代码来源:LinkItem.php

示例3: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $random = new Random();
     $max = $field_definition->getSetting('max_length');
     $values['value'] = $random->word(mt_rand(1, $max));
     return $values;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:10,代码来源:StringItem.php

示例4: buildEntityQuery

 /**
  * Builds an EntityQuery to get referenceable entities.
  *
  * @param string|null $match
  *   (Optional) Text to match the label against. Defaults to NULL.
  * @param string $match_operator
  *   (Optional) The operation the matching should be done with. Defaults
  *   to "CONTAINS".
  *
  * @return \Drupal\Core\Entity\Query\QueryInterface
  *   The EntityQuery object with the basic conditions and sorting applied to
  *   it.
  */
 public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS')
 {
     $target_type = $this->fieldDefinition->getSetting('target_type');
     $handler_settings = $this->fieldDefinition->getSetting('handler_settings');
     $entity_type = \Drupal::entityManager()->getDefinition($target_type);
     $query = \Drupal::entityQuery($target_type);
     if (!empty($handler_settings['target_bundles'])) {
         $query->condition($entity_type->getKey('bundle'), $handler_settings['target_bundles'], 'IN');
     }
     if (isset($match) && ($label_key = $entity_type->getKey('label'))) {
         $query->condition($label_key, $match, $match_operator);
     }
     // Add entity-access tag.
     $query->addTag($this->fieldDefinition->getSetting('target_type') . '_access');
     // Add the Selection handler for
     // entity_reference_query_entity_reference_alter().
     $query->addTag('entity_reference');
     $query->addMetaData('field_definition', $this->fieldDefinition);
     $query->addMetaData('entity_reference_selection_handler', $this);
     // Add the sort option.
     $handler_settings = $this->fieldDefinition->getSetting('handler_settings');
     if (!empty($handler_settings['sort'])) {
         $sort_settings = $handler_settings['sort'];
         if ($sort_settings['field'] != '_none') {
             $query->sort($sort_settings['field'], $sort_settings['direction']);
         }
     }
     return $query;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:42,代码来源:SelectionBase.php

示例5: createPayment

 /**
  * {@inheritdoc}
  */
 public function createPayment(FieldDefinitionInterface $field_definition)
 {
     /** @var \Drupal\payment\Entity\PaymentInterface $payment */
     $payment = $this->entityManager->getStorage('payment')->create(['bundle' => 'payment_reference']);
     /** @var \Drupal\payment_reference\Plugin\Payment\Type\PaymentReference $payment_type */
     $payment_type = $payment->getPaymentType();
     $payment_type->setEntityTypeId($field_definition->getFieldStorageDefinition()->getTargetEntityTypeId());
     $payment_type->setBundle($field_definition->getTargetBundle());
     $payment_type->setFieldName($field_definition->getName());
     $payment->setCurrencyCode($field_definition->getSetting('currency_code'));
     foreach ($field_definition->getSetting('line_items_data') as $line_item_data) {
         $line_item = $this->paymentLineItemManager->createInstance($line_item_data['plugin_id'], $line_item_data['plugin_configuration']);
         $payment->setLineItem($line_item);
     }
     return $payment;
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:19,代码来源:PaymentFactory.php

示例6: prepareTarget

 /**
  * {@inheritdoc}
  */
 protected static function prepareTarget(FieldDefinitionInterface $field_definition)
 {
     // Only reference content entities. Configuration entities will need custom
     // targets.
     $type = $field_definition->getSetting('target_type');
     if (!\Drupal::entityManager()->getDefinition($type)->isSubclassOf('\\Drupal\\Core\\Entity\\ContentEntityInterface')) {
         return;
     }
     return FieldTargetDefinition::createFromFieldDefinition($field_definition)->addProperty('target_id');
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:13,代码来源:EntityReference.php

示例7: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $type = $field_definition->getSetting('datetime_type');
     // Just pick a date in the past year. No guidance is provided by this Field
     // type.
     $timestamp = REQUEST_TIME - mt_rand(0, 86400 * 365);
     if ($type == DateTimeItem::DATETIME_TYPE_DATE) {
         $values['value'] = gmdate(DATETIME_DATE_STORAGE_FORMAT, $timestamp);
     } else {
         $values['value'] = gmdate(DATETIME_DATETIME_STORAGE_FORMAT, $timestamp);
     }
     return $values;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:16,代码来源:DateTimeItem.php

示例8: validateReferenceableEntities

 /**
  * {@inheritdoc}
  */
 public function validateReferenceableEntities(array $ids)
 {
     $handler_settings = $this->fieldDefinition->getSetting('handler_settings');
     $display_name = $handler_settings['view']['display_name'];
     $arguments = $handler_settings['view']['arguments'];
     $result = array();
     if ($this->initializeView(NULL, 'CONTAINS', 0, $ids)) {
         // Get the results.
         $entities = $this->view->executeDisplay($display_name, $arguments);
         $result = array_keys($entities);
     }
     return $result;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:16,代码来源:ViewsSelection.php

示例9: settingsForm

 /**
  * {@inheritdoc}
  */
 public static function settingsForm(FieldDefinitionInterface $field_definition)
 {
     $selection_handler_settings = $field_definition->getSetting('handler_settings');
     // Merge in default values.
     $selection_handler_settings += array('filter' => array('type' => '_none'));
     // Add user specific filter options.
     $form['filter']['type'] = array('#type' => 'select', '#title' => t('Filter by'), '#options' => array('_none' => t('- None -'), 'role' => t('User role')), '#ajax' => TRUE, '#limit_validation_errors' => array(), '#default_value' => $selection_handler_settings['filter']['type']);
     $form['filter']['settings'] = array('#type' => 'container', '#attributes' => array('class' => array('entity_reference-settings')), '#process' => array('_entity_reference_form_process_merge_parent'));
     if ($selection_handler_settings['filter']['type'] == 'role') {
         // Merge in default values.
         $selection_handler_settings['filter'] += array('role' => NULL);
         $form['filter']['settings']['role'] = array('#type' => 'checkboxes', '#title' => t('Restrict to the selected roles'), '#required' => TRUE, '#options' => array_diff_key(user_role_names(TRUE), array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID)), '#default_value' => $selection_handler_settings['filter']['role']);
     }
     $form += parent::settingsForm($field_definition);
     return $form;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:19,代码来源:UserSelection.php

示例10: isDestinationFieldCompatible

  /**
   * Check if a field on the entity type to update is a possible destination field.
   *
   * @todo Should this be on our FieldManager service?
   *
   * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $definition
   *  Field definition on entity type to update to check.
   * @param \Drupal\Core\Field\FieldDefinitionInterface $source_field
   *  Source field to check compatibility against. If none then check generally.
   *
   * @return bool
   */
  protected function isDestinationFieldCompatible(FieldStorageDefinitionInterface $definition, FieldDefinitionInterface $source_field = NULL) {
    // @todo Create field definition wrapper class to treat FieldDefinitionInterface and FieldStorageDefinitionInterface the same.
    if ($definition instanceof BaseFieldDefinition && $definition->isReadOnly()) {
      return FALSE;
    }
    // Don't allow updates on updates!
    if ($definition->getType() == 'entity_reference') {
      if ($definition->getSetting('target_type') == 'scheduled_update') {
        return FALSE;
      }
    }

    if ($source_field) {
      $matching_types = $this->getMatchingFieldTypes($source_field->getType());
      if (!in_array($definition->getType(), $matching_types)) {
        return FALSE;
      }
      // Check cardinality
      $destination_cardinality = $definition->getCardinality();
      $source_cardinality = $source_field->getFieldStorageDefinition()->getCardinality();
      // $destination_cardinality is unlimited. It doesn't matter what source is.
      if ($destination_cardinality != -1) {
        if ($source_cardinality == -1) {
          return FALSE;
        }
        if ($source_cardinality > $destination_cardinality) {
          return FALSE;
        }
      }


      switch($definition->getType()) {
        case 'entity_reference':
          // Entity reference field must match entity target types.
          if ($definition->getSetting('target_type') != $source_field->getSetting('target_type')) {
            return FALSE;
          }
          // @todo Check bundles
          break;
        // @todo Other type specific conditions?
      }

    }
    return TRUE;
  }
开发者ID:joebachana,项目名称:usatne,代码行数:57,代码来源:FieldUtilsTrait.php

示例11: getFieldSetting

 /**
  * Returns the value of a field setting.
  *
  * @param string $setting_name
  *   The setting name.
  *
  * @return mixed
  *   The setting value.
  */
 protected function getFieldSetting($setting_name)
 {
     return $this->fieldDefinition->getSetting($setting_name);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:13,代码来源:WidgetBase.php

示例12: getSelectionHandler

 /**
  * {@inheritdoc}
  */
 public function getSelectionHandler(FieldDefinitionInterface $field_definition, EntityInterface $entity = NULL)
 {
     $options = array('target_type' => $field_definition->getFieldStorageDefinition()->getSetting('target_type'), 'handler' => $field_definition->getSetting('handler'), 'handler_settings' => $field_definition->getSetting('handler_settings') ?: array(), 'entity' => $entity);
     return $this->getInstance($options);
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:8,代码来源:SelectionPluginManager.php

示例13: getWidgetOverride

 /**
  * Get the widget that should used for the default value.
  *
  * Returns null to use the default for the field.
  * @todo This is in here specifically to look at a solution for Workbench Moderation.
  *       Should this be function on the runner plugin?
  *       Or an old school alter hook?
  * @param $definition
  *
  * @return WidgetBase|null
  */
 protected function getWidgetOverride(FieldDefinitionInterface $definition) {
   if ($definition->getType() == 'entity_reference'
     && $definition->getSetting('target_type') == 'moderation_state') {
     $definition->setRequired(FALSE);
     $definition->setDescription('');
     return \Drupal::service('plugin.manager.field.widget')->getInstance(array('field_definition' => $definition));
   }
   return NUll;
 }
开发者ID:joebachana,项目名称:usatne,代码行数:20,代码来源:ScheduledUpdateTypeBaseForm.php

示例14: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $manager = \Drupal::service('plugin.manager.entity_reference_selection');
     // Instead of calling $manager->getSelectionHandler($field_definition)
     // replicate the behavior to be able to override the sorting settings.
     $options = array('target_type' => $field_definition->getFieldStorageDefinition()->getSetting('target_type'), 'handler' => $field_definition->getSetting('handler'), 'handler_settings' => $field_definition->getSetting('handler_settings') ?: array(), 'entity' => NULL);
     $entity_type = \Drupal::entityManager()->getDefinition($options['target_type']);
     $options['handler_settings']['sort'] = ['field' => $entity_type->getKey('id'), 'direction' => 'DESC'];
     $selection_handler = $manager->getInstance($options);
     // Select a random number of references between the last 50 referenceable
     // entities created.
     if ($referenceable = $selection_handler->getReferenceableEntities(NULL, 'CONTAINS', 50)) {
         $group = array_rand($referenceable);
         $values['target_id'] = array_rand($referenceable[$group]);
         return $values;
     }
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:20,代码来源:EntityReferenceItem.php


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