本文整理汇总了PHP中Drupal\node\NodeInterface类的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface类的具体用法?PHP NodeInterface怎么用?PHP NodeInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: access
/**
* {@inheritdoc}
*/
public function access(Route $route, AccountInterface $account, NodeInterface $node = NULL)
{
if ($node->bundle() && \Drupal::config('webform.settings')->get('node_' . $node->bundle())) {
return AccessResult::allowed();
}
return AccessResult::forbidden();
}
开发者ID:Progressable,项目名称:openway8,代码行数:10,代码来源:WebformNodeAccessCheck.php
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL)
{
$form['#title'] = $node->label();
$form['#node'] = $node;
$this->bookAdminTable($node, $form);
$form['save'] = array('#type' => 'submit', '#value' => $this->t('Save book pages'));
return $form;
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:11,代码来源:BookAdminEditForm.php
示例3: bookExportHtml
/**
* Generates HTML for export when invoked by book_export().
*
* The given node is embedded to its absolute depth in a top level section. For
* example, a child node with depth 2 in the hierarchy is contained in
* (otherwise empty) <div> elements corresponding to depth 0 and depth 1.
* This is intended to support WYSIWYG output - e.g., level 3 sections always
* look like level 3 sections, no matter their depth relative to the node
* selected to be exported as printer-friendly HTML.
*
* @param \Drupal\node\NodeInterface $node
* The node to export.
*
* @throws \Exception
* Thrown when the node was not attached to a book.
*
* @return array
* A render array representing the HTML for a node and its children in the
* book hierarchy.
*/
public function bookExportHtml(NodeInterface $node)
{
if (!isset($node->book)) {
throw new \Exception();
}
$tree = $this->bookManager->bookSubtreeData($node->book);
$contents = $this->exportTraverse($tree, array($this, 'bookNodeExport'));
return array('#theme' => 'book_export_html', '#title' => $node->label(), '#contents' => $contents, '#depth' => $node->book['depth'], '#cache' => ['tags' => $node->getEntityType()->getListCacheTags()]);
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:BookExport.php
示例4: access
/**
* Checks access to the node preview page.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
* @param \Drupal\node\NodeInterface $node_preview
* The node that is being previewed.
*
* @return string
* A \Drupal\Core\Access\AccessInterface constant value.
*/
public function access(AccountInterface $account, NodeInterface $node_preview)
{
if ($node_preview->isNew()) {
$access_controller = $this->entityManager->getAccessControlHandler('node');
return $access_controller->createAccess($node_preview->bundle(), $account, [], TRUE);
} else {
return $node_preview->access('update', $account, TRUE);
}
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:20,代码来源:NodePreviewAccessCheck.php
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL)
{
$this->attributeTable = 'uc_product_attributes';
$this->optionTable = 'uc_product_options';
$this->idField = 'nid';
$this->idValue = $node->id();
$attributes = uc_product_get_attributes($node->id());
return parent::buildForm($form, $form_state, $attributes);
}
开发者ID:pedrocones,项目名称:hydrotools,代码行数:12,代码来源:ProductAttributesAddForm.php
示例6: readNode
/**
* Marks a node as read by the current user right now.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request of the page.
* @param \Drupal\node\NodeInterface $node
* The node whose "last read" timestamp should be updated.
*/
public function readNode(Request $request, NodeInterface $node)
{
if ($this->currentUser()->isAnonymous()) {
throw new AccessDeniedHttpException();
}
// Update the history table, stating that this user viewed this node.
history_write($node->id());
return new JsonResponse((int) history_read($node->id()));
}
开发者ID:papillon-cendre,项目名称:d8,代码行数:17,代码来源:HistoryController.php
示例7: createNodeRevision
/**
* Creates a new revision for a given node.
*
* @param \Drupal\node\NodeInterface $node
* A node object.
*
* @return \Drupal\node\NodeInterface
* A node object with up to date revision information.
*/
protected function createNodeRevision(NodeInterface $node)
{
// Create revision with a random title and body and update variables.
$node->title = $this->randomMachineName();
$node->body = array('value' => $this->randomMachineName(32), 'format' => filter_default_format());
$node->setNewRevision();
$node->save();
return $node;
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:18,代码来源:NodeRevisionsAllTest.php
示例8: canViewRegistration
/**
* Determine if a user can view a given registration node.
*
* The user may view the node if they are the creator of it, or if they are
* an admin.
*
* @param \Drupal\node\NodeInterface $node
* @param \Drupal\Core\Session\AccountInterface $account
* @return \Drupal\Core\Access\AccessResult
*/
public function canViewRegistration(\Drupal\node\NodeInterface $node, \Drupal\Core\Session\AccountInterface $account)
{
if ($account->hasPermission('administer content')) {
return \Drupal\Core\Access\AccessResult::allowed();
}
if ($node->getOwner()->getAccountName() === $account->getAccountName()) {
return \Drupal\Core\Access\AccessResult::allowed();
}
return \Drupal\Core\Access\AccessResult::forbidden();
}
开发者ID:ABaldwinHunter,项目名称:durhamatletico-cms,代码行数:20,代码来源:RegistrationService.php
示例9: nodeGreeting
public function nodeGreeting(NodeInterface $node)
{
if ($node->isPublished()) {
$formatted = $node->body->processed;
foreach ($node->field_tags as $tag) {
$terms[] = $tag->entity->label();
}
return ['#theme' => 'greeting_node', '#title' => $node->label() . ' (' . $node->bundle() . ')', '#body' => $formatted, '#name' => $node->getOwner()->label(), '#terms' => $terms];
}
return ['#markup' => $this->t('Not published')];
}
开发者ID:japo32,项目名称:greeting,代码行数:11,代码来源:GreetingController.php
示例10: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL)
{
$query = \Drupal::request()->query->all();
$form['#action'] = Url::fromRoute('<current>')->setOptions(['query' => $query])->toString();
$form['nid'] = array('#type' => 'value', '#value' => $node->id());
$form['qty'] = array('#type' => 'value', '#value' => 1);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Add to cart'), '#id' => 'edit-submit-' . $node->id());
uc_form_alter($form, $form_state, $this->getFormId());
return $form;
}
开发者ID:pedrocones,项目名称:hydrotools,代码行数:14,代码来源:BuyItNowForm.php
示例11: schedule
/**
* Simulates the scheduled (un)publication of a node.
*
* @param \Drupal\node\NodeInterface $node
* The node to schedule.
* @param string $action
* The action to perform: either 'publish' or 'unpublish'. Defaults to
* 'publish'.
*
* @return \Drupal\node\NodeInterface
* The updated node, after scheduled (un)publication via a cron run.
*/
protected function schedule(NodeInterface $node, $action = 'publish')
{
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Simulate scheduling by setting the (un)publication date in the past and
// running cron.
$node->{$action . '_on'} = strtotime('-1 day');
$node->save();
scheduler_cron();
$node_storage->resetCache(array($node->id()));
return $node_storage->load($node->id());
}
开发者ID:blakefrederick,项目名称:sas-backend,代码行数:23,代码来源:SchedulerRevisioningTest.php
示例12: sorry
/**
* Text, if the user answered wrong.
*
* @param \Drupal\node\NodeInterface $node
* The node the client form belongs to.
* @return array
*/
public function sorry(NodeInterface $node)
{
$config = $this->config('field_quiz.settings');
$text = $config->get('field_quiz.test_answer_wrong');
$elements[] = array('#type' => 'html_tag', '#tag' => 'p', '#attributes' => array('style' => 'color: red'), '#value' => $this->t($text));
$url = Url::fromRoute('entity.node.canonical', array('node' => $node->id()));
$project_link = Link::fromTextAndUrl(t('Please try again.'), $url);
$project_link = $project_link->toRenderable();
// If you need some attributes.
$project_link['#attributes'] = array('class' => array('button', 'button-action', 'button--primary', 'button--small'));
$elements[] = array('#type' => 'html_tag', '#tag' => 'p', '#attributes' => array(), '#value' => render($project_link));
return $elements;
}
开发者ID:badelas,项目名称:afroweb,代码行数:20,代码来源:FieldQuizController.php
示例13: featuresOverview
/**
* Displays the product features tab on a product node edit form.
*/
public function featuresOverview(NodeInterface $node)
{
$header = array($this->t('Type'), $this->t('Description'), $this->t('Operations'));
$rows = [];
$features = uc_product_feature_load_multiple($node->id());
foreach ($features as $feature) {
$operations = array('edit' => array('title' => $this->t('Edit'), 'url' => Url::fromRoute('uc_product.feature_edit', ['node' => $node->id(), 'fid' => $feature->fid, 'pfid' => $feature->pfid])), 'delete' => array('title' => $this->t('Delete'), 'url' => Url::fromRoute('uc_product.feature_delete', ['node' => $node->id(), 'fid' => $feature->fid, 'pfid' => $feature->pfid])));
$rows[] = array(array('data' => uc_product_feature_data($feature->fid, 'title')), array('data' => array('#markup' => $feature->description)), array('data' => array('#type' => 'operations', '#links' => $operations)));
}
$build['features'] = array('#theme' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => array('class' => array('uc-product-features')), '#empty' => $this->t('No features found for this product.'));
$build['add_form'] = $this->formBuilder()->getForm('Drupal\\uc_product\\Form\\ProductFeatureAddForm', $node);
return $build;
}
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:16,代码来源:ProductFeaturesController.php
示例14: viewQuestion
/**
* Helper function to setup the faq question.
*
* @param array &$data
* Array reference to store display data in.
* @param \Drupal\node\NodeInterface $node
* The node object.
* @param string $path
* The path/url which the question should link to if links are disabled.
* @param string $anchor
* Link anchor to use in question links.
*/
public static function viewQuestion(&$data, \Drupal\node\NodeInterface $node, $path = NULL, $anchor = NULL)
{
$faq_settings = \Drupal::config('faq.settings');
$disable_node_links = $faq_settings->get('disable_node_links');
$question = '';
// Don't link to faq node, instead provide no link, or link to current page.
if ($disable_node_links) {
if (empty($path) && empty($anchor)) {
$question = $node->getTitle();
} elseif (empty($path)) {
// Can't seem to use l() function with empty string as screen-readers
// don't like it, so create anchor name manually.
$question = '<a id="' . $anchor . '"></a>' . $node->getTitle();
} else {
$options = array();
if ($anchor) {
$options['attributes'] = array('id' => $anchor);
}
$question = l($node->getTitle(), $path, $options);
}
} else {
$node_id = $node->id();
if (empty($anchor)) {
$question = l($node->getTitle(), "node/{$node_id})");
} else {
$question = l($node->getTitle(), "node/{$node_id}", array("attributes" => array("id" => "{$anchor}")));
}
}
$question = '<span datatype="" property="dc:title">' . $question . '</span>';
$detailed_question = $node->get('field_detailed_question')->value;
if ($faq_settings->get('display') != 'hide_answer' && !empty($detailed_question) && $faq_settings->get('question_length') == 'both') {
$question .= '<div class="faq-detailed-question">' . $detailed_question . '</div>';
}
$data['question'] = SafeMarkup::set($question);
}
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:47,代码来源:FaqViewer.php
示例15: addAnotherAccess
/**
* Takes the user to the node creation page for the type of a given node.
*/
public function addAnotherAccess(NodeInterface $node)
{
if (!$node->access('create')) {
return AccessResult::forbidden();
}
$config = \Drupal::config('addanother.settings');
$account = \Drupal::currentUser();
$type = $node->getType();
if (\Drupal::routeMatch()->getRouteName() == 'entity.node.edit_form' && !$config->get('tab_edit.' . $type)) {
return AccessResult::forbidden();
}
if ($config->get('tab.' . $type) && $account->hasPermission('use add another')) {
return AccessResult::allowed();
}
return AccessResult::forbidden();
}
开发者ID:mkdok,项目名称:d8-addanother,代码行数:19,代码来源:AddAnotherController.php
示例16: webform_paymethod_select_continue
public function webform_paymethod_select_continue(\Drupal\node\NodeInterface $node, $submission, $page_num)
{
// We can't use a simple drupal_get_form() because we wan't to enter the form
// at a specific $page_num.
$form_state = [];
$args = [$node, $submission, TRUE, TRUE];
$form_state['build_info']['args'] = $args;
$form_state['storage']['component_tree'] = [];
$form_state['storage']['page_count'] = 1;
$form_state['storage']['preview'] = !empty($node->webform['preview']);
_webform_components_tree_build($node->webform['components'], $form_state['storage']['component_tree'], 0, $form_state['storage']['page_count']);
$form_state['storage']['page_num'] = $page_num;
if (\Drupal::moduleHandler()->moduleExists('webform_steps')) {
$form_state['steps_finished'] = $page_num - 1;
}
return \Drupal::formBuilder()->buildForm('webform_client_form_' . $node->id(), $form_state);
}
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:17,代码来源:DefaultController.php
示例17: nodeHug
public function nodeHug(NodeInterface $node)
{
if ($node->isPublished()) {
// These are the same!
$body = $node->body->value;
$body = $node->body[0]->value;
// But we really want...
$formatted = $node->body->processed;
$terms = [];
foreach ($node->field_tags as $tag) {
$terms[] = $tag->entity->label();
}
$message = $this->t('Everyone hug @name because @reasons!', ['@name' => $node->getOwner()->label(), '@reasons' => implode(', ', $terms)]);
return ['#title' => $node->label() . ' (' . $node->bundle() . ')', '#markup' => $message . $formatted];
}
return $this->t('Not published');
}
开发者ID:sriharisahu,项目名称:hugs,代码行数:17,代码来源:HugsController.php
示例18: testBasicSettings
/**
* Test the basic settings.
*/
public function testBasicSettings() {
$manage_display = '/admin/structure/types/manage/article/display';
$this->drupalGet($manage_display);
$this->drupalPostAjaxForm(NULL, [], 'body_settings_edit');
$this->drupalPostAjaxForm(NULL, [
'fields[body][label]' => 'above',
'fields[body][settings_edit_form][third_party_settings][fences][fences_field_tag]' => 'article',
'fields[body][settings_edit_form][third_party_settings][fences][fences_field_classes]' => 'my-field-class',
'fields[body][settings_edit_form][third_party_settings][fences][fences_field_item_tag]' => 'code',
'fields[body][settings_edit_form][third_party_settings][fences][fences_field_item_classes]' => 'my-field-item-class',
'fields[body][settings_edit_form][third_party_settings][fences][fences_label_tag]' => 'h2',
'fields[body][settings_edit_form][third_party_settings][fences][fences_label_classes]' => 'my-label-class',
], ['body_plugin_settings_update' => 'Update']);
$this->drupalPostForm(NULL, [], 'Save');
$expected_field_markup = <<<EOD
<article class="my-field-class clearfix text-formatted field field--name-body field--type-text-with-summary field--label-above field__items">
<h2 class="my-label-class field__label">Body</h2>
<code class="my-field-item-class field__item">
<p>Body field value.</p>
</code>
</article>
EOD;
$page = $this->drupalGet('/node/' . $this->node->id());
$this->assertTrue(strpos($this->stripWhitespace($page), $this->stripWhitespace($expected_field_markup)) !== FALSE, 'Found the correct field markup on the page.');
}
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:31,代码来源:IntegrationTest.php
示例19: testConfigurableEventHandler
/**
* Tests ConfigurableEventHandlerEntityBundle.
*
* Test that rules are triggered correctly based upon the fully qualified
* event name as well as the base event name.
*
* @todo Add integrity check that node.field_integer is detected by Rules.
*/
public function testConfigurableEventHandler()
{
// Create rule1 with the 'rules_entity_presave:node--page' event.
$rule1 = $this->expressionManager->createRule();
$rule1->addAction('rules_test_log', ContextConfig::create()->map('message', 'node.field_integer.0.value'));
$config_entity1 = $this->storage->create(['id' => 'test_rule1']);
$config_entity1->set('events', [['event_name' => 'rules_entity_presave:node--page']]);
$config_entity1->set('expression', $rule1->getConfiguration());
$config_entity1->save();
// Create rule2 with the 'rules_entity_presave:node' event.
$rule2 = $this->expressionManager->createRule();
$rule2->addAction('rules_test_log', ContextConfig::create()->map('message', 'node.field_integer.1.value'));
$config_entity2 = $this->storage->create(['id' => 'test_rule2']);
$config_entity2->set('events', [['event_name' => 'rules_entity_presave:node']]);
$config_entity2->set('expression', $rule2->getConfiguration());
$config_entity2->save();
// The logger instance has changed, refresh it.
$this->logger = $this->container->get('logger.channel.rules');
// Add node.field_integer.0.value to rules log message, read result.
$this->node->field_integer->setValue(['0' => 11, '1' => 22]);
// Trigger node save.
$entity_type_id = $this->node->getEntityTypeId();
$event = new EntityEvent($this->node, [$entity_type_id => $this->node]);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch("rules_entity_presave:{$entity_type_id}", $event);
// Test that the action in the rule1 logged node value.
$this->assertRulesLogEntryExists(11, 1);
// Test that the action in the rule2 logged node value.
$this->assertRulesLogEntryExists(22, 0);
}
开发者ID:Progressable,项目名称:openway8,代码行数:38,代码来源:ConfigurableEventHandlerTest.php
示例20: build
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match)
{
$breadcrumb = new Breadcrumb();
$links[] = Link::createFromRoute(t('Home'), '<front>');
// Articles page is a view.
$links[] = Link::createFromRoute(t('Articles'), 'view.articles.page_1');
$links[] = Link::createFromRoute($this->node->label(), '<none>');
$breadcrumb->setLinks($links);
return $breadcrumb;
}
开发者ID:chi-teck,项目名称:drupal-code-generator,代码行数:13,代码来源:_breadcrumb_builder.php
注:本文中的Drupal\node\NodeInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论