當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FieldItemBase::onDependencyRemoval方法代碼示例

本文整理匯總了PHP中Drupal\Core\Field\FieldItemBase::onDependencyRemoval方法的典型用法代碼示例。如果您正苦於以下問題:PHP FieldItemBase::onDependencyRemoval方法的具體用法?PHP FieldItemBase::onDependencyRemoval怎麽用?PHP FieldItemBase::onDependencyRemoval使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Field\FieldItemBase的用法示例。


在下文中一共展示了FieldItemBase::onDependencyRemoval方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onDependencyRemoval

 /**
  * {@inheritdoc}
  */
 public static function onDependencyRemoval(FieldDefinitionInterface $field_definition, array $dependencies)
 {
     $changed = parent::onDependencyRemoval($field_definition, $dependencies);
     $entity_manager = \Drupal::entityManager();
     $target_entity_type = $entity_manager->getDefinition($field_definition->getFieldStorageDefinition()->getSetting('target_type'));
     // Try to update the default value config dependency, if possible.
     if ($default_value = $field_definition->getDefaultValueLiteral()) {
         foreach ($default_value as $key => $value) {
             if (is_array($value) && isset($value['target_uuid'])) {
                 $entity = $entity_manager->loadEntityByUuid($target_entity_type->id(), $value['target_uuid']);
                 // @see \Drupal\Core\Field\EntityReferenceFieldItemList::processDefaultValue()
                 if ($entity && isset($dependencies[$entity->getConfigDependencyKey()][$entity->getConfigDependencyName()])) {
                     unset($default_value[$key]);
                     $changed = TRUE;
                 }
             }
         }
         if ($changed) {
             $field_definition->setDefaultValue($default_value);
         }
     }
     // Update the 'target_bundles' handler setting if a bundle config dependency
     // has been removed.
     $bundles_changed = FALSE;
     $handler_settings = $field_definition->getSetting('handler_settings');
     if (!empty($handler_settings['target_bundles'])) {
         if ($bundle_entity_type_id = $target_entity_type->getBundleEntityType()) {
             if ($storage = $entity_manager->getStorage($bundle_entity_type_id)) {
                 foreach ($storage->loadMultiple($handler_settings['target_bundles']) as $bundle) {
                     if (isset($dependencies[$bundle->getConfigDependencyKey()][$bundle->getConfigDependencyName()])) {
                         unset($handler_settings['target_bundles'][$bundle->id()]);
                         // If this bundle is also used in the 'auto_create_bundle'
                         // setting, disable the auto-creation feature completely.
                         $auto_create_bundle = !empty($handler_settings['auto_create_bundle']) ? $handler_settings['auto_create_bundle'] : FALSE;
                         if ($auto_create_bundle && $auto_create_bundle == $bundle->id()) {
                             $handler_settings['auto_create'] = NULL;
                             $handler_settings['auto_create_bundle'] = NULL;
                         }
                         $bundles_changed = TRUE;
                         // In case we deleted the only target bundle allowed by the field
                         // we have to log a critical message because the field will not
                         // function correctly anymore.
                         if ($handler_settings['target_bundles'] === []) {
                             \Drupal::logger('entity_reference')->critical('The %target_bundle bundle (entity type: %target_entity_type) was deleted. As a result, the %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', ['%target_bundle' => $bundle->label(), '%target_entity_type' => $bundle->getEntityType()->getBundleOf(), '%field_name' => $field_definition->getName(), '%entity_type' => $field_definition->getTargetEntityTypeId(), '%bundle' => $field_definition->getTargetBundle()]);
                         }
                     }
                 }
             }
         }
     }
     if ($bundles_changed) {
         $field_definition->setSetting('handler_settings', $handler_settings);
     }
     $changed |= $bundles_changed;
     return $changed;
 }
開發者ID:318io,項目名稱:318-io,代碼行數:59,代碼來源:EntityReferenceItem.php


注:本文中的Drupal\Core\Field\FieldItemBase::onDependencyRemoval方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。