本文整理汇总了PHP中Drupal\Core\Entity\EntityManagerInterface::getViewModes方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::getViewModes方法的具体用法?PHP EntityManagerInterface::getViewModes怎么用?PHP EntityManagerInterface::getViewModes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::getViewModes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: settingsForm
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state)
{
$options = [];
foreach ($this->entityManager->getViewModes($this->configuration['entity_type']) as $id => $view_mode) {
$options[$id] = $view_mode['label'];
}
return ['view_mode' => ['#type' => 'select', '#title' => t('View mode'), '#description' => t('Select view mode to be used when rendering entities.'), '#default_value' => $this->configuration['view_mode'], '#options' => $options]];
}
示例2: buildOptionsForm_summary_options
/**
* Return the main options, which are shown in the summary title.
*/
public function buildOptionsForm_summary_options()
{
$view_modes = $this->entityManager->getViewModes($this->entityTypeId);
$options = array();
foreach ($view_modes as $mode => $settings) {
$options[$mode] = $settings['label'];
}
return $options;
}
示例3: getViewModeOptions
/**
* Retrieves the list of available view modes for the current node.
*
* @param EntityInterface $node
* The node being previewed.
*
* @return array
* List of available view modes for the current node.
*/
protected function getViewModeOptions(EntityInterface $node)
{
$load_ids = array();
$view_mode_options = array();
// Load all the node's view modes.
$view_modes = $this->entityManager->getViewModes('node');
// Get the list of available view modes for the current node's bundle.
$ids = $this->configFactory->listAll('core.entity_view_display.node.' . $node->bundle());
foreach ($ids as $id) {
$config_id = str_replace('core.entity_view_display' . '.', '', $id);
$load_ids[] = $config_id;
}
$displays = entity_load_multiple('entity_view_display', $load_ids);
// Generate the display options array.
foreach ($displays as $display) {
$view_mode_name = $display->get('mode');
// Skip view modes that are not used in the front end.
if (in_array($view_mode_name, array('rss', 'search_index'))) {
continue;
}
if ($display->status()) {
$view_mode_options[$view_mode_name] = $view_mode_name == 'default' ? t('Default') : $view_modes[$view_mode_name]['label'];
}
}
return $view_mode_options;
}
示例4: isViewModeCacheable
/**
* Returns TRUE if the view mode is cacheable.
*
* @param string $view_mode
* Name of the view mode that should be rendered.
*
* @return bool
* TRUE if the view mode can be cached, FALSE otherwise.
*/
protected function isViewModeCacheable($view_mode)
{
if ($view_mode == 'default') {
// The 'default' is not an actual view mode.
return TRUE;
}
$view_modes_info = $this->entityManager->getViewModes($this->entityTypeId);
return !empty($view_modes_info[$view_mode]['cache']);
}
示例5: addDefaultField
/**
* {@inheritdoc}
*/
public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment')
{
$comment_type_storage = $this->entityManager->getStorage('comment_type');
if ($comment_type = $comment_type_storage->load($comment_type_id)) {
if ($comment_type->getTargetEntityTypeId() !== $entity_type) {
throw new \InvalidArgumentException(String::format('The given comment type id %id can only be used with the %entity_type entity type', array('%id' => $comment_type_id, '%entity_type' => $entity_type)));
}
} else {
// Silently create the comment-type for the calling code.
$comment_type_storage->create(array('id' => $comment_type_id, 'label' => Unicode::ucfirst($comment_type_id), 'target_entity_type_id' => $entity_type, 'description' => 'Default comment field'))->save();
}
// Make sure the field doesn't already exist.
if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
// Add a default comment field for existing node comments.
$field_storage = $this->entityManager->getStorage('field_storage_config')->create(array('entity_type' => $entity_type, 'field_name' => $field_name, 'type' => 'comment', 'translatable' => TRUE, 'settings' => array('comment_type' => $comment_type_id)));
// Create the field.
$field_storage->save();
}
// Make sure the instance doesn't already exist.
if (!array_key_exists($field_name, $this->entityManager->getFieldDefinitions($entity_type, $bundle))) {
$field = $this->entityManager->getStorage('field_config')->create(array('label' => 'Comments', 'description' => '', 'field_name' => $field_name, 'entity_type' => $entity_type, 'bundle' => $bundle, 'required' => 1, 'default_value' => array(array('status' => $default_value, 'cid' => 0, 'last_comment_name' => '', 'last_comment_timestamp' => 0, 'last_comment_uid' => 0))));
$field->save();
// Assign widget settings for the 'default' form mode.
entity_get_form_display($entity_type, $bundle, 'default')->setComponent($field_name, array('type' => 'comment_default', 'weight' => 20))->save();
// The comment field should be hidden in all other form displays.
foreach ($this->entityManager->getFormModes($entity_type) as $id => $form_mode) {
$display = entity_get_form_display($entity_type, $bundle, $id);
// Only update existing displays.
if ($display && !$display->isNew()) {
$display->removeComponent($field_name)->save();
}
}
// Set default to display comment list.
entity_get_display($entity_type, $bundle, 'default')->setComponent($field_name, array('label' => 'above', 'type' => 'comment_default', 'weight' => 20))->save();
// The comment field should be hidden in all other view displays.
foreach ($this->entityManager->getViewModes($entity_type) as $id => $view_mode) {
$display = entity_get_display($entity_type, $bundle, $id);
// Only update existing displays.
if ($display && !$display->isNew()) {
$display->removeComponent($field_name)->save();
}
}
}
$this->addBodyField($comment_type_id);
}
示例6: alterLocalTasks
/**
* Alters the base_route definition for field_ui local tasks.
*
* @param array $local_tasks
* An array of local tasks plugin definitions, keyed by plugin ID.
*/
public function alterLocalTasks(&$local_tasks)
{
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($route_name = $entity_type->get('field_ui_base_route')) {
$local_tasks["field_ui.fields:overview_{$entity_type_id}"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:form_display_overview_{$entity_type_id}"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:display_overview_{$entity_type_id}"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:field_form_display_default_{$entity_type_id}"]['base_route'] = $route_name;
$local_tasks["field_ui.fields:field_display_default_{$entity_type_id}"]['base_route'] = $route_name;
foreach ($this->entityManager->getFormModes($entity_type_id) as $form_mode => $form_mode_info) {
$local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $entity_type_id]['base_route'] = $route_name;
}
foreach ($this->entityManager->getViewModes($entity_type_id) as $view_mode => $form_mode_info) {
$local_tasks['field_ui.fields:field_display_' . $view_mode . '_' . $entity_type_id]['base_route'] = $route_name;
}
}
}
}
示例7: alterLocalTasks
/**
* Alters the base_route definition for field_ui local tasks.
*
* @param array $local_tasks
* An array of local tasks plugin definitions, keyed by plugin ID.
*/
public function alterLocalTasks(&$local_tasks)
{
foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) {
if ($entity_info->isFieldable() && $entity_info->hasLinkTemplate('admin-form')) {
$admin_form = $entity_info->getLinkTemplate('admin-form');
$local_tasks["field_ui.fields:overview_{$entity_type}"]['base_route'] = $admin_form;
$local_tasks["field_ui.fields:form_display_overview_{$entity_type}"]['base_route'] = $admin_form;
$local_tasks["field_ui.fields:display_overview_{$entity_type}"]['base_route'] = $admin_form;
$local_tasks["field_ui.fields:field_form_display_default_{$entity_type}"]['base_route'] = $admin_form;
$local_tasks["field_ui.fields:field_display_default_{$entity_type}"]['base_route'] = $admin_form;
foreach ($this->entityManager->getFormModes($entity_type) as $form_mode => $form_mode_info) {
$local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $entity_type]['base_route'] = $admin_form;
}
foreach ($this->entityManager->getViewModes($entity_type) as $view_mode => $form_mode_info) {
$local_tasks['field_ui.fields:field_display_' . $view_mode . '_' . $entity_type]['base_route'] = $admin_form;
}
}
}
}
示例8: getViewModes
/**
* {@inheritdoc}
*/
public function getViewModes($entity_type_id)
{
return $this->entityManager->getViewModes($entity_type_id);
}
示例9: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
global $base_url;
$my_path = drupal_get_path('module', 'sharethis');
// First, setup variables we will need.
// Get the path variables setup.
// Load the css and js for our module's configuration.
$config = $this->config('sharethis.settings');
$current_options_array = $this->sharethisManager->getOptions();
// Create the variables related to button choice.
$button_choice = $current_options_array['buttons'];
// Create the variables related to services chosen.
$service_string = $current_options_array['services'];
$service_string_markup = "";
foreach (explode(",", $service_string) as $name => $string) {
$key = explode(":", Unicode::substr($string, 0, -1));
$key = $key[1];
$service_string_markup[] = $key;
}
// Create the variables for publisher keys.
$publisher = $current_options_array['publisherID'];
// Create the variables for teasers.
$form = array();
$form['options'] = array('#type' => 'fieldset', '#title' => t('Display'));
$form['options']['button_option'] = array('#required' => TRUE, '#type' => 'radios', '#options' => array('stbc_large' => t('Large Chicklets'), 'stbc_' => t('Small Chicklets'), 'stbc_button' => t('Classic Buttons'), 'stbc_vcount' => t('Vertical Counters'), 'stbc_hcount' => t('Horizontal Counters'), 'stbc_custom' => t('Custom Buttons via CSS')), '#default_value' => $button_choice, '#title' => t("Choose a button style:"), '#prefix' => '<div class="st_widgetContain"><div class="st_spriteCover"><img id="stb_sprite" class="st_buttonSelectSprite ' . $button_choice . '" src="' . $base_url . '/' . $my_path . '/img/preview_sprite.png" /></div><div class="st_widgetPic"><img class="st_buttonSelectImage" src="' . $base_url . '/' . $my_path . '/img/preview_bg.png" /></div>', '#suffix' => '</div>');
$form['options']['service_option'] = array('#description' => t('<b>Add</b> a service by selecting it on the right and clicking the <i>left arrow</i>. <b>Remove</b> it by clicking the <i>right arrow</i>.<br /><b>Change the order</b> of services under "Selected Services" by using the <i>up</i> and <i>down</i> arrows.'), '#required' => TRUE, '#type' => 'textfield', '#prefix' => '<div>', '#suffix' => '</div><div id="myPicker"></div>', '#title' => t("Choose Your Services."), '#default_value' => $service_string, '#maxlength' => 1024);
$form['options']['option_extras'] = array('#title' => $this->t('Extra services'), '#description' => $this->t('Select additional services which will be available. These are not officially supported by ShareThis, but are available.'), '#type' => 'checkboxes', '#options' => ['Google Plus One:plusone' => $this->t('Google Plus One'), 'Facebook Like:fblike' => $this->t('Facebook Like')], '#default_value' => $config->get('option_extras'));
$form['options']['callesi'] = array('#type' => 'hidden', '#default_value' => $current_options_array['callesi']);
$form['additional_settings'] = array('#type' => 'vertical_tabs');
$form['context'] = array('#type' => 'details', '#title' => t('Context'), '#group' => 'additional_settings', '#description' => t('Configure where the ShareThis widget should appear.'));
$form['context']['location'] = array('#title' => t('Location'), '#type' => 'radios', '#options' => array('content' => t('Node content'), 'block' => t('Block'), 'links' => t('Links area')), '#default_value' => $config->get('location'));
// Add an information section for each location type, each dependent on the
// currently selected location.
foreach (array('links', 'content', 'block') as $location_type) {
$form['context'][$location_type]['#type'] = 'container';
$form['context'][$location_type]['#states']['visible'][':input[name="location"]'] = array('value' => $location_type);
}
// Add help text for the 'content' location.
$form['context']['content']['help'] = array('#markup' => t('When using the Content location, you must place the ShareThis links in the <a href="@url">Manage Display</a> section of each content type.'), '#weight' => 10, '#prefix' => '<em>', '#suffix' => '</em>');
// Add help text for the 'block' location.
$form['context']['block']['#children'] = 'You must choose which region to display the in from the Blocks administration';
$entity_bundles = $this->entityManager->getBundleInfo('node');
// Add checkboxes for each view mode of each bundle.
$entity_modes = $this->entityManager->getViewModes('node');
$modes = array();
foreach ($entity_modes as $mode => $mode_info) {
$modes[$mode] = $mode_info['label'];
}
// Get a list of content types and view modes.
foreach ($entity_bundles as $bundle => $bundle_info) {
$form['context']['links'][$bundle . '_options'] = array('#title' => t('%label View Modes', array('%label' => $bundle_info['label'])), '#description' => t('Select which view modes the ShareThis widget should appear on for %label nodes.', array('%label' => $bundle_info['label'])), '#type' => 'checkboxes', '#options' => $modes, '#default_value' => $config->get('sharethisnodes.' . $bundle));
}
// Allow the user to choose which content types will have ShareThis added
// when using the 'Content' location.
$content_types = array();
$enabled_content_types = $current_options_array['node_types'];
foreach ($entity_bundles as $bundle => $bundle_info) {
$content_types[$bundle] = $this->t($bundle_info['label']);
}
$form['context']['content']['node_types'] = array('#title' => $this->t('Node Types'), '#description' => $this->t('Select which node types the ShareThis widget should appear on.'), '#type' => 'checkboxes', '#options' => $content_types, '#default_value' => $enabled_content_types);
$form['context']['comments'] = array('#title' => $this->t('Comments'), '#type' => 'checkbox', '#default_value' => $config->get('comments'), '#description' => $this->t('Display ShareThis on comments.'), '#access' => $this->moduleHandler->moduleExists('comment'));
$sharethis_weight_list = array(-100, -50, -25, -10, 0, 10, 25, 50, 100);
$form['context']['weight'] = array('#title' => $this->t('Weight'), '#description' => $this->t('The weight of the widget determines the location on the page where it will appear.'), '#required' => FALSE, '#type' => 'select', '#options' => array_combine($sharethis_weight_list, $sharethis_weight_list), '#default_value' => $config->get('weight'));
$form['advanced'] = array('#type' => 'details', '#title' => $this->t('Advanced'), '#group' => 'additional_settings', '#description' => $this->t('The advanced settings can usually be ignored if you have no need for them.'));
$form['advanced']['publisherID'] = array('#title' => $this->t("Insert a publisher key (optional)."), '#description' => $this->t("When you install the module, we create a random publisher key. You can register the key with ShareThis by contacting customer support. Otherwise, you can go to <a href='http://www.sharethis.com/account'>ShareThis</a> and create an account.<br />Your official publisher key can be found under 'My Account'.<br />It allows you to get detailed analytics about sharing done on your site."), '#type' => 'textfield', '#default_value' => $publisher);
$form['advanced']['late_load'] = array('#title' => $this->t('Late Load'), '#description' => $this->t("You can change the order in which ShareThis widget loads on the user's browser. By default the ShareThis widget loader loads as soon as the browser encounters the JavaScript tag; typically in the tag of your page. ShareThis assets are generally loaded from a CDN closest to the user. However, if you wish to change the default setting so that the widget loads after your web-page has completed loading then you simply tick this option."), '#type' => 'checkbox', '#default_value' => $config->get('late_load'));
$form['advanced']['twitter_suffix'] = array('#title' => $this->t("Twitter Suffix"), '#description' => $this->t("Optionally append a Twitter handle, or text, so that you get pinged when someone shares an article. Example: <em>via @YourNameHere</em>"), '#type' => 'textfield', '#default_value' => $config->get('twitter_suffix'));
$form['advanced']['twitter_handle'] = array('#title' => $this->t('Twitter Handle'), '#description' => $this->t('Twitter handle to use when sharing.'), '#type' => 'textfield', '#default_value' => $config->get('twitter_handle'));
$form['advanced']['twitter_recommends'] = array('#title' => $this->t('Twitter recommends'), '#description' => $this->t('Specify a twitter handle to be recommended to the user.'), '#type' => 'textfield', '#default_value' => $config->get('twitter_recommends'));
$form['advanced']['option_onhover'] = array('#type' => 'checkbox', '#title' => $this->t('Display ShareThis widget on hover'), '#description' => $this->t('If disabled, the ShareThis widget will be displayed on click instead of hover.'), '#default_value' => $config->get('option_onhover'));
$form['advanced']['option_neworzero'] = array('#type' => 'checkbox', '#title' => $this->t('Display count "0" instead of "New"'), '#description' => $this->t('Display a zero (0) instead of "New" in the count for content not yet shared.'), '#default_value' => $config->get('option_neworzero'));
$form['advanced']['option_shorten'] = array('#type' => 'checkbox', '#title' => $this->t('Display short URL'), '#description' => $this->t('Display either the full or the shortened URL.'), '#default_value' => $config->get('option_shorten'));
$form['advanced']['cns'] = array('#title' => $this->t('<b>CopyNShare </b><sup>(<a href="http://support.sharethis.com/customer/portal/articles/517332-share-widget-faqs#copynshare" target="_blank">?</a>)</sup>'), '#type' => 'checkboxes', '#prefix' => '<div id="st_cns_settings">', '#suffix' => '</div><div class="st_cns_container">
<p>CopyNShare is the new ShareThis widget feature that enables you to track the shares that occur when a user copies and pastes your website\'s <u>URL</u> or <u>Content</u>. <br/>
<u>Site URL</u> - ShareThis adds a special #hashtag at the end of your address bar URL to keep track of where your content is being shared on the web.<br/>
<u>Site Content</u> - It enables the pasting of "See more: YourURL#SThashtag" after user copies-and-pastes text. When a user copies text within your site, a "See more: yourURL.com#SThashtag" will appear after the pasted text. <br/>
Please refer the <a href="http://support.sharethis.com/customer/portal/articles/517332-share-widget-faqs#copynshare" target="_blank">CopyNShare FAQ</a> for more details.</p>
</div>', '#options' => array('donotcopy' => $this->t("Measure copy & shares of your site's Content"), 'hashaddress' => $this->t("Measure copy & shares of your site's URLs")), '#default_value' => $config->get('cns'));
$form['#attached']['drupalSettings']['sharethis']['service_string_markup'] = $service_string_markup;
$form['#attached']['library'][] = 'sharethis/drupal.sharethisform';
$form['#attached']['library'][] = 'sharethis/drupal.sharethispicker';
$form['#attached']['library'][] = 'sharethis/drupal.sharethispickerexternal';
return parent::buildForm($form, $form_state);
}