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


PHP FormatterBase::t方法代碼示例

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


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

示例1: captionSettings

 /**
  * Returns the form element for caption settings.
  *
  * @param \Drupal\Core\Field\FormatterBase $formatter
  * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
  *
  * @return array
  */
 protected function captionSettings(FormatterBase $formatter, FieldDefinitionInterface $field_definition)
 {
     $field_settings = $field_definition->getSettings();
     // Set the caption options.
     $caption_options = array(0 => $formatter->t('None'), 1 => $formatter->t('Image title'), 'alt' => $formatter->t('Image ALT attribute'));
     // Remove the options that are not available.
     $action_fields = array();
     if ($field_settings['title_field'] == FALSE) {
         unset($caption_options[1]);
         // User action required on the image title.
         $action_fields[] = 'title';
     }
     if ($field_settings['alt_field'] == FALSE) {
         unset($caption_options['alt']);
         // User action required on the image alt.
         $action_fields[] = 'alt';
     }
     // Create the caption element.
     $element['caption'] = array('#title' => $formatter->t('Choose a caption source'), '#type' => 'select', '#options' => $caption_options);
     // If the image field doesn't have all of the suitable caption sources, tell the user.
     if ($action_fields) {
         $action_text = $formatter->t('enable the @action_field field', array('@action_field' => join(' and/or ', $action_fields)));
         /* This may be a base field definition (e.g. in Views UI) which means it
          * is not associated with a bundle and will not have the toUrl() method.
          * So we need to check for the existence of the method before we can
          * build a link to the image field edit form.
          */
         if (method_exists($field_definition, 'toUrl')) {
             // Build the link to the image field edit form for this bundle.
             $rel = "{$field_definition->getTargetEntityTypeId()}-field-edit-form";
             $action = $field_definition->toLink($action_text, $rel, array('fragment' => 'edit-settings-alt-field', 'query' => \Drupal::destination()->getAsArray()))->toRenderable();
         } else {
             // Just use plain text if we can't build the field edit link.
             $action = ['#markup' => $action_text];
         }
         $element['caption']['#description'] = $formatter->t('You need to @action for this image field to be able to use it as a caption.', array('@action' => render($action)));
         // If there are no suitable caption sources, disable the caption element.
         if (count($action_fields) >= 2) {
             $element['caption']['#disabled'] = TRUE;
         }
     } else {
         $element['caption']['#default_value'] = $formatter->getSetting('caption');
     }
     return $element;
 }
開發者ID:r-daneelolivaw,項目名稱:chalk,代碼行數:53,代碼來源:FlexsliderFormatterTrait.php


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