本文整理汇总了PHP中Drupal\node\Entity\NodeType::loadMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeType::loadMultiple方法的具体用法?PHP NodeType::loadMultiple怎么用?PHP NodeType::loadMultiple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\Entity\NodeType
的用法示例。
在下文中一共展示了NodeType::loadMultiple方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: settingsForm
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state)
{
$options = array();
$types = NodeType::loadMultiple();
$comment_fields = $this->commentManager ? $this->commentManager->getFields('node') : array();
$map = array($this->t('Hidden'), $this->t('Closed'), $this->t('Open'));
foreach ($types as $type) {
$options[$type->id()] = array('type' => array('#markup' => $this->t($type->label())));
if ($this->commentManager) {
$fields = array();
foreach ($comment_fields as $field_name => $info) {
// Find all comment fields for the bundle.
if (in_array($type->id(), $info['bundles'])) {
$instance = FieldConfig::loadByName('node', $type->id(), $field_name);
$default_mode = reset($instance->default_value);
$fields[] = SafeMarkup::format('@field: !state', array('@field' => $instance->label(), '!state' => $map[$default_mode['status']]));
}
}
// @todo Refactor display of comment fields.
if (!empty($fields)) {
$options[$type->id()]['comments'] = array('data' => array('#theme' => 'item_list', '#items' => $fields));
} else {
$options[$type->id()]['comments'] = $this->t('No comment fields');
}
}
}
if (empty($options)) {
$create_url = $this->urlGenerator->generateFromRoute('node.type_add');
$this->setMessage($this->t('You do not have any content types that can be generated. <a href="@create-type">Go create a new content type</a> already!</a>', array('@create-type' => $create_url)), 'error', FALSE);
return;
}
$header = array('type' => $this->t('Content type'));
if ($this->commentManager) {
$header['comments'] = array('data' => $this->t('Comments'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM));
}
$form['node_types'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options);
$form['kill'] = array('#type' => 'checkbox', '#title' => $this->t('<strong>Delete all content</strong> in these content types before generating new content.'), '#default_value' => $this->getSetting('kill'));
$form['num'] = array('#type' => 'textfield', '#title' => $this->t('How many nodes would you like to generate?'), '#default_value' => $this->getSetting('num'), '#size' => 10);
$options = array(1 => $this->t('Now'));
foreach (array(3600, 86400, 604800, 2592000, 31536000) as $interval) {
$options[$interval] = \Drupal::service('date.formatter')->formatInterval($interval, 1) . ' ' . $this->t('ago');
}
$form['time_range'] = array('#type' => 'select', '#title' => $this->t('How far back in time should the nodes be dated?'), '#description' => $this->t('Node creation dates will be distributed randomly from the current time, back to the selected time.'), '#options' => $options, '#default_value' => 604800);
$form['max_comments'] = array('#type' => $this->moduleHandler->moduleExists('comment') ? 'textfield' : 'value', '#title' => $this->t('Maximum number of comments per node.'), '#description' => $this->t('You must also enable comments for the content types you are generating. Note that some nodes will randomly receive zero comments. Some will receive the max.'), '#default_value' => $this->getSetting('max_comments'), '#size' => 3, '#access' => $this->moduleHandler->moduleExists('comment'));
$form['title_length'] = array('#type' => 'textfield', '#title' => $this->t('Maximum number of words in titles'), '#default_value' => $this->getSetting('title_length'), '#size' => 10);
$form['add_alias'] = array('#type' => 'checkbox', '#disabled' => !$this->moduleHandler->moduleExists('path'), '#description' => $this->t('Requires path.module'), '#title' => $this->t('Add an url alias for each node.'), '#default_value' => FALSE);
$form['add_statistics'] = array('#type' => 'checkbox', '#title' => $this->t('Add statistics for each node (node_counter table).'), '#default_value' => TRUE, '#access' => $this->moduleHandler->moduleExists('statistics'));
$options = array();
// We always need a language
$languages = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL);
foreach ($languages as $langcode => $language) {
$options[$langcode] = $language->getName();
}
$default_language = \Drupal::service('language.default')->get();
$default_langcode = $default_language->getId();
$form['add_language'] = array('#type' => 'select', '#title' => $this->t('Set language on nodes'), '#multiple' => TRUE, '#description' => $this->t('Requires locale.module'), '#options' => $options, '#default_value' => array($default_langcode));
$form['submit'] = array('#type' => 'submit', '#value' => $this->t('Generate'), '#tableselect' => TRUE);
$form['#redirect'] = FALSE;
return $form;
}
示例2: getOptions
/**
* {@inheritdoc}
*/
public function getOptions()
{
$sharethis_config = $this->configFactory->get('sharethis.settings');
$view_modes = array();
foreach (array_keys(NodeType::loadMultiple()) as $type) {
$view_modes[$type] = array('article' => 'article', 'page' => 'page');
}
return ['buttons' => $sharethis_config->get('button_option', 'stbc_button'), 'publisherID' => $sharethis_config->get('publisherID'), 'services' => $sharethis_config->get('service_option'), 'option_extras' => $sharethis_config->get('option_extras'), 'widget' => $sharethis_config->get('widget_option'), 'onhover' => $sharethis_config->get('option_onhover'), 'neworzero' => $sharethis_config->get('option_neworzero'), 'twitter_suffix' => $sharethis_config->get('twitter_suffix'), 'twitter_handle' => $sharethis_config->get('twitter_handle'), 'twitter_recommends' => $sharethis_config->get('twitter_recommends'), 'late_load' => $sharethis_config->get('late_load'), 'view_modes' => $view_modes, 'cns' => $sharethis_config->get('cns'), 'callesi' => NULL == $sharethis_config->get('cns') ? 1 : 0, 'node_types' => $sharethis_config->get('node_types'), 'shorten' => $sharethis_config->get('option_shorten')];
}
示例3: permissions
/**
* Define permissions.
*/
public function permissions()
{
$permissions = array('assign domain editors' => array('title' => $this->t('Assign additional editors to assigned domains')), 'assign editors to any domain' => array('title' => $this->t('Assign additional editors to any domains')), 'publish to any domain' => array('title' => $this->t('Publish to any domain')), 'publish to any assigned domain' => array('title' => $this->t('Publish content to any assigned domain')), 'create domain content' => array('title' => $this->t('Create any content on assigned domains')), 'edit domain content' => array('title' => $this->t('Edit any content on assigned domains')), 'delete domain content' => array('title' => $this->t('Delete any content on assigned domains')), 'view unpublished domain content' => array('title' => $this->t('View unpublished content on assigned domains')));
// Generate standard node permissions for all applicable node types.
foreach (NodeType::loadMultiple() as $type) {
$permissions += $this->nodePermissions($type);
}
return $permissions;
}
示例4: nodeTypePermissions
/**
* Gets an array of node type permissions.
*
* @return array
* The node type permissions.
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
*/
public function nodeTypePermissions()
{
$perms = array();
// Generate node permissions for all node types.
foreach (NodeType::loadMultiple() as $type) {
$perms += $this->buildPermissions($type);
}
return $perms;
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$types = array();
foreach (NodeType::loadMultiple() as $type) {
$types[$type->get('type')] = $type->get('name');
}
$config = \Drupal::config('hello_world.settings');
$form['types'] = array('#type' => 'checkboxes', '#title' => t('Content types'), '#description' => t('Content types where you want to append \'Hello world\''), '#options' => $types, '#default_value' => $config->get('types'));
return parent::buildForm($form, $form_state);
}
示例6: testNodeTypeGetFunctions
/**
* Ensures that node type functions (node_type_get_*) work correctly.
*
* Load available node types and validate the returned data.
*/
function testNodeTypeGetFunctions()
{
$node_types = NodeType::loadMultiple();
$node_names = node_type_get_names();
$this->assertTrue(isset($node_types['article']), 'Node type article is available.');
$this->assertTrue(isset($node_types['page']), 'Node type basic page is available.');
$this->assertEqual($node_types['article']->label(), $node_names['article'], 'Correct node type base has been returned.');
$article = NodeType::load('article');
$this->assertEqual($node_types['article'], $article, 'Correct node type has been returned.');
$this->assertEqual($node_types['article']->label(), $article->label(), 'Correct node type name has been returned.');
}
示例7: query
public function query()
{
$table = $this->ensureMyTable();
$where_per_type = array();
foreach (NodeType::loadMultiple() as $type) {
$type_id = $type->id();
$where_per_type[] = "({$table}.type = '{$type_id}' AND ***VIEWUNPUBLISHED_{$type_id}*** = 1)";
}
$where_per_type = implode(' OR ', $where_per_type);
$this->query->addWhereExpression($this->options['group'], "{$table}.status = 1 OR ({$table}.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND ***VIEW_OWN_UNPUBLISHED_NODES*** = 1) OR ***BYPASS_NODE_ACCESS*** = 1 OR {$where_per_type}");
}
示例8: permissions
public function permissions()
{
$permissions = [];
$nodeTypes = NodeType::loadMultiple();
foreach ($nodeTypes as $nodeType) {
$permission = 'view any ' . $nodeType->id() . ' content';
$permissions[$permission] = ['title' => $this->t('<em>@type_label</em>: View any content', ['@type_label' => $nodeType->label()])];
$permission = 'view own ' . $nodeType->id() . ' content';
$permissions[$permission] = ['title' => $this->t('<em>@type_label</em>: View own content', ['@type_label' => $nodeType->label()])];
}
return $permissions;
}
示例9: buildForm
/**
* Form constructor.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* The form structure.
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$sitemap = \Drupal::service('custom_sitemap.sitemap');
$entity_types = $sitemap->get_entity_types();
$custom_links = $sitemap->get_custom_links();
$form = array('entity-types' => array('#type' => 'vertical_tabs'), 'node' => array('#type' => 'details', '#title' => $this->t('Content types'), '#group' => 'entity-types'), 'taxonomy_term' => array('#type' => 'details', '#title' => $this->t('Vocabularies'), '#group' => 'entity-types'));
/** @var NodeType[] $content_types */
$content_types = NodeType::loadMultiple();
$this->setEntityTypeDetailForm($form, 'node', $content_types, $entity_types['node']);
/** @var Vocabulary[] $vocabularies */
$vocabularies = Vocabulary::loadMultiple();
$this->setEntityTypeDetailForm($form, 'taxonomy_term', $vocabularies, $entity_types['taxonomy_term']);
return parent::buildForm($form, $form_state);
}
示例10: setUp
protected function setUp()
{
parent::setUp();
// Create an article content type only if it does not yet exist, so that
// child classes may specify the standard profile.
$types = NodeType::loadMultiple();
if (empty($types['article'])) {
$this->drupalCreateContentType(array('type' => 'article', 'name' => t('Article')));
}
// Create two test users.
$this->adminUser = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer comment types', 'administer comment fields', 'administer comment display', 'skip comment approval', 'post comments', 'access comments', 'access content'));
$this->webUser = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments', 'skip comment approval', 'access content'));
// Create comment field on article.
$this->addDefaultCommentField('node', 'article');
// Create a test node authored by the web user.
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()));
}
示例11: buildForm
public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
$config = $this->config('photos_access.settings');
$form['privacy'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => t('Privacy settings'),
'#description' => t('Enabled photos access privacy settings for the following content types.'),
];
$types = \Drupal\node\Entity\NodeType::loadMultiple();
foreach ($types as $type) {
$form['privacy']['photos_access_' . $type->id()] = array(
'#title' => $type->label(),
'#type' => 'checkbox',
'#default_value' => $config->get('photos_access_' . $type->id()),
);
}
return parent::buildForm($form, $form_state);
}
示例12: hook_entity_extra_field_info_alter
/**
* Alter "pseudo-field" components on content entities.
*
* @param array $info
* The array structure is identical to that of the return value of
* \Drupal\Core\Entity\EntityManagerInterface::getExtraFields().
*
* @see hook_entity_extra_field_info()
*/
function hook_entity_extra_field_info_alter(&$info)
{
// Force node title to always be at the top of the list by default.
foreach (NodeType::loadMultiple() as $bundle) {
if (isset($info['node'][$bundle->type]['form']['title'])) {
$info['node'][$bundle->type]['form']['title']['weight'] = -20;
}
}
}
示例13: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
// Honeypot Configuration.
$form['configuration'] = ['#type' => 'fieldset', '#title' => t('Honeypot Configuration'), '#collapsible' => TRUE, '#collapsed' => FALSE];
$form['configuration']['protect_all_forms'] = ['#type' => 'checkbox', '#title' => t('Protect all forms with Honeypot'), '#description' => t('Enable Honeypot protection for ALL forms on this site (it is best to only enable Honeypot for the forms you need below).'), '#default_value' => $this->config('honeypot.settings')->get('protect_all_forms')];
$form['configuration']['protect_all_forms']['#description'] .= '<br />' . t('<strong>Page caching will be disabled on any page where a form is present if the Honeypot time limit is not set to 0.</strong>');
$form['configuration']['log'] = ['#type' => 'checkbox', '#title' => t('Log blocked form submissions'), '#description' => t('Log submissions that are blocked due to Honeypot protection.'), '#default_value' => $this->config('honeypot.settings')->get('log')];
$form['configuration']['element_name'] = ['#type' => 'textfield', '#title' => t('Honeypot element name'), '#description' => t("The name of the Honeypot form field. It's usually most effective to use a generic name like email, homepage, or link, but this should be changed if it interferes with fields that are already in your forms. Must not contain spaces or special characters."), '#default_value' => $this->config('honeypot.settings')->get('element_name'), '#required' => TRUE, '#size' => 30];
$form['configuration']['time_limit'] = ['#type' => 'textfield', '#title' => t('Honeypot time limit'), '#description' => t('Minimum time required before form should be considered entered by a human instead of a bot. Set to 0 to disable.'), '#default_value' => $this->config('honeypot.settings')->get('time_limit'), '#required' => TRUE, '#size' => 5, '#field_suffix' => t('seconds')];
$form['configuration']['time_limit']['#description'] .= '<br />' . t('<strong>Page caching will be disabled if there is a form protected by time limit on the page.</strong>');
// Honeypot Enabled forms.
$form_settings = $this->config('honeypot.settings')->get('form_settings');
$form['form_settings'] = ['#type' => 'fieldset', '#title' => t('Honeypot Enabled Forms'), '#description' => t("Check the boxes next to individual forms on which you'd like Honeypot protection enabled."), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, '#states' => ['invisible' => ['input[name="protect_all_forms"]' => ['checked' => TRUE]]]];
// Generic forms.
$form['form_settings']['general_forms'] = ['#markup' => '<h5>' . t('General Forms') . '</h5>'];
// User register form.
$form['form_settings']['user_register_form'] = ['#type' => 'checkbox', '#title' => t('User Registration form'), '#default_value' => $this->getFormSettingsValue($form_settings, 'user_register_form')];
// User password form.
$form['form_settings']['user_pass'] = ['#type' => 'checkbox', '#title' => t('User Password Reset form'), '#default_value' => $this->getFormSettingsValue($form_settings, 'user_pass')];
// If webform.module enabled, add webforms.
// TODO D8 - See if D8 version of Webform.module still uses this form ID.
if (\Drupal::moduleHandler()->moduleExists('webform')) {
$form['form_settings']['webforms'] = ['#type' => 'checkbox', '#title' => t('Webforms (all)'), '#default_value' => $this->getFormSettingsValue($form_settings, 'webforms')];
}
// If contact.module enabled, add contact forms.
if (\Drupal::moduleHandler()->moduleExists('contact')) {
$form['form_settings']['contact_forms'] = ['#markup' => '<h5>' . t('Contact Forms') . '</h5>'];
$bundles = \Drupal::entityManager()->getBundleInfo('contact_message');
$formController = \Drupal::entityManager()->getFormObject('contact_message', 'default');
foreach ($bundles as $bundle_key => $bundle) {
$stub = entity_create('contact_message', ['contact_form' => $bundle_key]);
$formController->setEntity($stub);
$form_id = $formController->getFormId();
$form['form_settings'][$form_id] = ['#type' => 'checkbox', '#title' => SafeMarkup::checkPlain($bundle['label']), '#default_value' => $this->getFormSettingsValue($form_settings, $form_id)];
}
}
// Node types for node forms.
if (\Drupal::moduleHandler()->moduleExists('node')) {
$types = NodeType::loadMultiple();
if (!empty($types)) {
// Node forms.
$form['form_settings']['node_forms'] = ['#markup' => '<h5>' . t('Node Forms') . '</h5>'];
foreach ($types as $type) {
$id = $type->getEntityTypeId() . '_node_form';
$form['form_settings'][$id] = ['#type' => 'checkbox', '#title' => t('@name node form', ['@name' => $type->label()]), '#default_value' => $this->getFormSettingsValue($form_settings, $id)];
}
}
}
// Comment types for comment forms.
if (\Drupal::moduleHandler()->moduleExists('comment')) {
$types = CommentType::loadMultiple();
if (!empty($types)) {
$form['form_settings']['comment_forms'] = ['#markup' => '<h5>' . t('Comment Forms') . '</h5>'];
foreach ($types as $type) {
$id = 'comment_' . $type->id() . '_form';
$form['form_settings'][$id] = ['#type' => 'checkbox', '#title' => t('@name comment form', ['@name' => $type->label()]), '#default_value' => $this->getFormSettingsValue($form_settings, $id)];
}
}
}
// Store the keys we want to save in configuration when form is submitted.
$keys_to_save = array_keys($form['configuration']);
foreach ($keys_to_save as $key => $key_to_save) {
if (strpos($key_to_save, '#') !== FALSE) {
unset($keys_to_save[$key]);
}
}
$form_state->setStorage(['keys' => $keys_to_save]);
// For now, manually add submit button. Hopefully, by the time D8 is
// released, there will be something like system_settings_form() in D7.
$form['actions']['#type'] = 'container';
$form['actions']['submit'] = ['#type' => 'submit', '#value' => t('Save configuration')];
return $form;
}
示例14: at_core_form_system_theme_settings_alter
/**
* Implementation of hook_form_system_theme_settings_alter()
*
* @param $form
* Nested array of form elements that comprise the form.
*
* @param $form_state
* A keyed array containing the current state of the form.
*/
function at_core_form_system_theme_settings_alter(&$form, &$form_state)
{
// Set the theme name.
$build_info = $form_state->getBuildInfo();
$theme = $build_info['args'][0];
// Instantiate our Theme info object.
$themeInfo = new ThemeInfo($theme);
$getThemeInfo = $themeInfo->getThemeInfo('info');
// Get this themes config settings
$config = \Drupal::config($theme . '.settings')->get('settings');
// Common paths.
$at_core_path = drupal_get_path('theme', 'at_core');
$subtheme_path = drupal_get_path('theme', $theme);
$generated_files_path = NULL;
// Path to save generated CSS files. We don't want this happening for at_core or the generator.
if (isset($getThemeInfo['subtheme type']) && $getThemeInfo['subtheme type'] === 'adaptive_subtheme') {
$directoryOperations = new DirectoryOperations();
$generated_files_path = $directoryOperations->directoryPrepare($backup_file_path = array($subtheme_path, 'styles/css/generated'));
}
// Get the active themes regions so we can use this in
// various other places.
$theme_regions = system_region_list($theme, $show = REGIONS_VISIBLE);
// Active themes active blocks
$theme_blocks = entity_load_multiple_by_properties('block', ['theme' => $theme]);
// Check for breakpoints module and set a warning and a flag to disable much
// of the theme settings if its not available.
$breakpoints_module = \Drupal::moduleHandler()->moduleExists('breakpoint');
if ($breakpoints_module == TRUE) {
$breakpoint_groups = \Drupal::service('breakpoint.manager')->getGroups();
$breakpoints = array();
// Unset core breakpoint groups due to notices and other issues, until this
// is resolved: SEE: https://www.drupal.org/node/2379283
unset($breakpoint_groups['toolbar']);
unset($breakpoint_groups['seven']);
unset($breakpoint_groups['bartik']);
// Set breakpoint options, we use these in layout and other extensions like
// Responsive menus.
foreach ($breakpoint_groups as $group_key => $group_values) {
$breakpoints[$group_key] = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup($group_key);
}
foreach ($breakpoints as $group => $breakpoint_values) {
if ($breakpoint_values !== array()) {
$breakpoint_options[$group] = $group;
}
}
} else {
drupal_set_message(t('Adaptivetheme requires the <b>Breakpoint module</b>. Open the <a href="!extendpage" target="_blank">Extend</a> page and enable Breakpoint.', array('!extendpage' => base_path() . 'admin/modules')), 'warning');
}
// Get node types (bundles).
$node_types = \Drupal\node\Entity\NodeType::loadMultiple();
// View or "Display modes".
// TODO entityManager() is deprecated, but how to replace?
$node_view_modes = \Drupal::entityManager()->getViewModes('node');
// Unset unwanted view modes
unset($node_view_modes['rss']);
unset($node_view_modes['search_index']);
unset($node_view_modes['search_result']);
// Set a class on the form for the current admin theme, note if this is set to
// "Default theme" the result is always 0.
$system_theme_config = \Drupal::config('system.theme');
$admin_theme = $system_theme_config->get('admin');
if (!empty($admin_theme)) {
$admin_theme_class = 'admin-theme--' . Html::cleanCssIdentifier($admin_theme);
$form['#attributes'] = array('class' => array($admin_theme_class));
}
// Attached required CSS and JS.
$form['#attached']['library'][] = 'at_core/at.appearance_settings';
// AT Core
if ($theme == 'at_core') {
$form['at_core']['message'] = array('#type' => 'container', '#markup' => t('AT Core has no configuration and cannot be used as a front end theme - it is a base them only. Use the <b>AT Theme Generator</b> to generate or clone a theme to get started.'));
// Hide form items.
$form['theme_settings']['#attributes']['class'] = array('visually-hidden');
$form['logo']['#attributes']['class'] = array('visually-hidden');
$form['favicon']['#attributes']['class'] = array('visually-hidden');
$form['actions']['#attributes']['class'] = array('visually-hidden');
}
// AT Subtheme
if (isset($getThemeInfo['subtheme type'])) {
if ($getThemeInfo['subtheme type'] !== 'adaptive_generator') {
// Pass in the generated files path to values and settings.
$form['at']['settings_generated_files_path'] = array('#type' => 'hidden', '#value' => $generated_files_path);
// Extension settings.
require_once $at_core_path . '/forms/ext/extension_settings.php';
// Layouts.
require_once $at_core_path . '/forms/layout/layouts.php';
// Basic settings - move into details wrapper and collapse.
$form['basic_settings'] = array('#type' => 'details', '#title' => t('Basic Settings'), '#open' => FALSE);
$form['theme_settings']['#open'] = FALSE;
$form['theme_settings']['#group'] = 'basic_settings';
$form['logo']['#open'] = FALSE;
$form['logo']['#group'] = 'basic_settings';
//.........这里部分代码省略.........