本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::get方法的具体用法?PHP EntityInterface::get怎么用?PHP EntityInterface::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLabelAndConfig
/**
* Renders the Metatag defaults lable plus its configuration.
*
* @param EntityInterface $entity
* The Metatag defaults entity.
* @return
* Render array for a table cell.
*/
public function getLabelAndConfig(EntityInterface $entity)
{
$output = '<div>';
$prefix = '';
$inherits = '';
if ($entity->id() != 'global') {
$prefix = '<div class="indentation"></div>';
$inherits .= 'Global';
}
if (strpos($entity->id(), '__') !== FALSE) {
$prefix .= '<div class="indentation"></div>';
list($entity_label, $bundle_label) = explode(': ', $entity->get('label'));
$inherits .= ', ' . $entity_label;
}
$output .= '<div>
<p>Inherits meta tags from: ' . $inherits . '</p>
</div>';
$tags = $entity->get('tags');
if (count($tags)) {
$output .= '<table>
<tbody>';
foreach ($tags as $tag_id => $tag_value) {
$output .= '<tr><td>' . $tag_id . ':</td><td>' . $tag_value . '</td></tr>';
}
$output .= '</tbody></table>';
}
$output .= '</div></div>';
return array('data' => array('#type' => 'details', '#prefix' => $prefix, '#title' => $this->getLabel($entity), 'config' => array('#markup' => $output)));
}
示例2: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row = array();
$row['date']['data'] = $entity->get('activity_date')->view(array('label' => 'hidden'));
$row['title']['data'] = array('#type' => 'link', '#title' => SafeMarkup::checkPlain($entity->label()), '#url' => $entity->urlInfo());
$row['type'] = $entity->get('type')->entity->label();
return $row + parent::buildRow($entity);
}
示例3: buildRow
/**
* Builds a row for an entity in the entity listing.
*
* @param EntityInterface $entity
* The entity for which to build the row.
*
* @return array
* A render array of the table row for displaying the entity.
*
* @see Drupal\Core\Entity\EntityListController::render()
*/
public function buildRow(EntityInterface $entity)
{
$row['label'] = $entity->label();
$row['machine_name'] = $entity->id();
$row['description'] = $entity->get('description');
$row['source_type'] = $entity->get('source_type');
return $row + parent::buildRow($entity);
}
示例4: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $medium_editor)
{
$row['label'] = $medium_editor->label();
$row['description'] = String::checkPlain($medium_editor->get('description'));
$row['toolbar'] = String::checkPlain(implode(', ', $medium_editor->getToolbar()));
$row['delay'] = String::checkPlain($medium_editor->get('delay'));
return $row + parent::buildRow($medium_editor);
}
示例5: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row = array();
$row['label']['data'] = array('#type' => 'link', '#title' => SafeMarkup::checkPlain($entity->label()), '#url' => $entity->urlInfo());
$row['type'] = SafeMarkup::checkPlain($entity->get('type')->entity->label());
$row['changed'] = $this->dateFormatter->format($entity->get('changed')->value, 'short');
return $row + parent::buildRow($entity);
}
示例6: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row = array();
if (!empty($this->weightKey)) {
// Override default values to markup elements.
$row['#attributes']['class'][] = 'draggable';
$row['#weight'] = $entity->get($this->weightKey);
// Add weight column.
$row['weight'] = array('#type' => 'weight', '#title' => t('Weight for @title', array('@title' => $entity->label())), '#title_display' => 'invisible', '#default_value' => $entity->get($this->weightKey), '#attributes' => array('class' => array('weight')));
}
return $row + parent::buildRow($entity);
}
示例7: get
/**
* {@inheritdoc}
*/
public function get($property_name)
{
if (!isset($this->entity)) {
throw new MissingDataException("Unable to get property {$property_name} as no entity has been provided.");
}
if (!$this->entity instanceof FieldableEntityInterface) {
// @todo: Add support for config entities in
// https://www.drupal.org/node/1818574.
throw new \InvalidArgumentException("Unable to get unknown property {$property_name}.");
}
// This will throw an exception for unknown fields.
return $this->entity->get($property_name);
}
示例8: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\simple_oauth\Entity\AccessToken */
$type = $entity->get('resource')->target_id == 'authentication' ? t('Refresh Token') : t('Access Token');
$row['type'] = $type;
$user = $entity->get('auth_user_id')->entity;
$row['user'] = $this->l($user->label(), new Url('entity.user.canonical', array('user' => $user->id())));
$owner = $entity->get('user_id')->entity;
$row['owner'] = $this->l($owner->label(), new Url('entity.user.canonical', array('user' => $owner->id())));
$row['id'] = $entity->id();
$row['name'] = $this->l($entity->label(), new Url('entity.access_token.edit_form', array('access_token' => $entity->id())));
$row['resource'] = $entity->get('resource')->entity->label();
return $row + parent::buildRow($entity);
}
示例9: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$theme = $entity->get('theme');
$plugin_definition = $entity->getPlugin()->getPluginDefinition();
$row['label'] = array('data' => $this->getLabel($entity), 'class' => 'table-filter-text-source');
$row['theme'] = array('data' => String::checkPlain($this->themes[$theme]->info['name']), 'class' => 'table-filter-text-source');
$row['category'] = array('data' => String::checkPlain($plugin_definition['category']), 'class' => 'table-filter-text-source');
$row['operations']['data'] = $this->buildOperations($entity);
return $row;
}
示例10: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row['label'] = $entity->label();
$row['id'] = $entity->id();
$row['type'] = $entity->get('type');
if ($info = $entity->getPluginDefinition()) {
$row['type'] = $info['title'];
}
return $row + parent::buildRow($entity);
}
示例11: assignPlayerToTeam
/**
* Assign a player to a team.
*
* Incoming entity will be a registration node with a reference
* to a team. When that's updated, load the team node and make
* sure the player is assigned/removed from the team node.
*
* TODO: This does not update the previous revision, so manual
* clean up is needed if the player is switched to a different
* team.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
*/
public function assignPlayerToTeam(\Drupal\Core\Entity\EntityInterface $entity)
{
$team_nid = $entity->get('field_registration_teams')->getValue();
if (isset($team_nid[0]['target_id'])) {
$team_node = \Drupal\node\Entity\Node::load($team_nid[0]['target_id']);
$player_nids = array_merge($team_node->get('field_players')->getValue(), array(array('target_id' => $entity->getOwnerId())));
$player_nids = array_map("unserialize", array_unique(array_map("serialize", $player_nids)));
$team_node->get('field_players')->setValue($player_nids);
$team_node->save();
}
}
示例12: examples
/**
* {@inheritdoc}
*/
public function examples(EntityInterface $entity)
{
$examples = array();
foreach ($this->nameExamples() as $index => $example_name) {
$formatted = SafeMarkup::checkPlain(NameFormatParser::parse($example_name, $entity->get('pattern')));
if (empty($formatted)) {
$formatted = '<em><<empty>></em>';
}
$examples[] = $formatted . " <sup>{$index}</sup>";
}
return $examples;
}
示例13: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\checkstyle\Entity\CheckstyleIssue */
$row['id'] = $this->l($entity->id(), new Url('entity.checkstyle_issue.edit_form', array('checkstyle_issue' => $entity->id())));
/** @var EntityReferenceFieldItemList $ref_field */
$ref_field = $entity->get('issue_type');
/** @var Node $ref_entity */
$ref_entity = Node::load($ref_field->get(0)->getValue()['target_id']);
#krumo($ref_entity->get('issue_type')->getValue()[0]['value']);
#krumo( $ref_entity->get('title'));
# @todo find decent way of displaying this stuff
$row['issue_type'] = $ref_entity->get('issue_type')->getValue()[0]['value'];
return $row + parent::buildRow($entity);
}
示例14: checkAccess
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
{
// Permissions only apply to own entities.
if ($account->id() != $entity->get('auth_user_id')->target_id) {
return AccessResult::forbidden();
}
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermission($account, 'view own access token entities');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit own access token entities');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete own access token entities');
}
return AccessResult::allowed();
}
示例15: testFieldEmpty
/**
* Tests that the prepareView() formatter method still fires for empty values.
*/
function testFieldEmpty()
{
// Uses \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldEmptyFormatter.
$display = array('label' => 'hidden', 'type' => 'field_empty_test', 'settings' => array('test_empty_string' => '**EMPTY FIELD**' . $this->randomName()));
// $this->entity is set by the setUp() method and by default contains 4
// numeric values. We only want to test the display of this one field.
$this->render($this->entity->get($this->field_name)->view($display));
// The test field by default contains values, so should not display the
// default "empty" text.
$this->assertNoText($display['settings']['test_empty_string']);
// Now remove the values from the test field and retest.
$this->entity->{$this->field_name} = array();
$this->entity->save();
$this->render($this->entity->get($this->field_name)->view($display));
// This time, as the field values have been removed, we *should* show the
// default "empty" text.
$this->assertText($display['settings']['test_empty_string']);
}