本文整理汇总了PHP中Drupal\Component\Serialization\Json类的典型用法代码示例。如果您正苦于以下问题:PHP Json类的具体用法?PHP Json怎么用?PHP Json使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Json类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $display_variant_id = NULL)
{
$form = parent::buildForm($form, $form_state, $page, $display_variant_id);
// Set up the attributes used by a modal to prevent duplication later.
$attributes = ['class' => ['use-ajax'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 'auto'])];
$add_button_attributes = NestedArray::mergeDeep($attributes, ['class' => ['button', 'button--small', 'button-action']]);
if ($this->displayVariant instanceof ConditionVariantInterface) {
if ($selection_conditions = $this->displayVariant->getSelectionConditions()) {
// Selection conditions.
$form['selection_section'] = ['#type' => 'details', '#title' => $this->t('Selection Conditions'), '#open' => TRUE];
$form['selection_section']['add'] = ['#type' => 'link', '#title' => $this->t('Add new selection condition'), '#url' => Url::fromRoute('page_manager.selection_condition_select', ['page' => $this->page->id(), 'display_variant_id' => $this->displayVariant->id()]), '#attributes' => $add_button_attributes, '#attached' => ['library' => ['core/drupal.ajax']]];
$form['selection_section']['table'] = ['#type' => 'table', '#header' => [$this->t('Label'), $this->t('Description'), $this->t('Operations')], '#empty' => $this->t('There are no selection conditions.')];
$form['selection_section']['selection_logic'] = ['#type' => 'radios', '#options' => ['and' => $this->t('All conditions must pass'), 'or' => $this->t('Only one condition must pass')], '#default_value' => $this->displayVariant->getSelectionLogic()];
$form['selection_section']['selection'] = ['#tree' => TRUE];
foreach ($selection_conditions as $selection_id => $selection_condition) {
$row = [];
$row['label']['#markup'] = $selection_condition->getPluginDefinition()['label'];
$row['description']['#markup'] = $selection_condition->summary();
$operations = [];
$operations['edit'] = ['title' => $this->t('Edit'), 'url' => Url::fromRoute('page_manager.selection_condition_edit', ['page' => $this->page->id(), 'display_variant_id' => $this->displayVariant->id(), 'condition_id' => $selection_id]), 'attributes' => $attributes];
$operations['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('page_manager.selection_condition_delete', ['page' => $this->page->id(), 'display_variant_id' => $this->displayVariant->id(), 'condition_id' => $selection_id]), 'attributes' => $attributes];
$row['operations'] = ['#type' => 'operations', '#links' => $operations];
$form['selection_section']['table'][$selection_id] = $row;
}
}
}
return $form;
}
示例2: getRequestParams
protected function getRequestParams(Request $request)
{
$params = array_merge(['where' => [], 'limit' => null], $request->query->all());
$params['where'] = Json::decode($params['where']);
ksort($params['where']);
return $params;
}
示例3: testFieldFormatter
/**
* Test base logic for the Juicebox field formatter.
*/
public function testFieldFormatter()
{
$node = $this->node;
$xml_path = 'juicebox/xml/field/node/' . $node->id() . '/' . $this->instFieldName . '/full';
$xml_url = \Drupal::url('juicebox.xml_field', array('entityType' => 'node', 'entityId' => $node->id(), 'fieldName' => $this->instFieldName, 'displayName' => 'full'));
// Get the urls to the test image and thumb derivative used by default.
$uri = \Drupal\file\Entity\File::load($node->{$this->instFieldName}[0]->target_id)->getFileUri();
$test_image_url = entity_load('image_style', 'juicebox_medium')->buildUrl($uri);
$test_thumb_url = entity_load('image_style', 'juicebox_square_thumb')->buildUrl($uri);
// Check for correct embed markup.
$this->drupalGet('node/' . $node->id());
$this->assertRaw(trim(json_encode(array('configUrl' => $xml_url)), '{}"'), 'Gallery setting found in Drupal.settings.');
$this->assertRaw('id="node--' . $node->id() . '--' . str_replace('_', '-', $this->instFieldName) . '--full"', 'Embed code wrapper found.');
$this->assertRaw(Html::escape(file_url_transform_relative($test_image_url)), 'Test image found in embed code');
// Check for correct XML.
$this->drupalGet($xml_path);
$this->assertRaw('<?xml version="1.0" encoding="UTF-8"?>', 'Valid XML detected.');
$this->assertRaw('imageURL="' . Html::escape($test_image_url), 'Test image found in XML.');
$this->assertRaw('thumbURL="' . Html::escape($test_thumb_url), 'Test thumbnail found in XML.');
// Check for contextual links in embed code. It might we worth checking if
// there is a more programmatic way to build the related id at some point.
$this->drupalLogin($this->webUser);
// Need access to contextual links.
$this->drupalGet('node/' . $node->id());
$id = 'juicebox_xml_field:entityType=node&entityId=' . $node->id() . '&fieldName=' . $this->instFieldName . '&displayName=full:langcode=en|juicebox_conf_field_node:view_mode_name=default&node_type=' . $this->instBundle . ':langcode=en|juicebox_conf_global::langcode=en';
$this->assertRaw('<div data-contextual-id="' . Html::escape($id) . '"></div>', 'Correct contextual link placeholders found.');
$json = Json::decode($this->renderContextualLinks(array($id), 'node/' . $node->id()));
$this->assertResponse(200);
$this->assertTrue(preg_match('|/juicebox/xml/field/node/' . $node->id() . '/' . $this->instFieldName . '/full.*/admin/structure/types/manage/' . $this->instBundle . '/display/default.*/admin/config/media/juicebox|', $json[$id]), 'Correct contextual links found.');
}
示例4: testFileFieldFormatter
/**
* Tests file field formatter Entity Embed Display plugins.
*/
public function testFileFieldFormatter()
{
// Ensure that file field formatters are available as plugins.
$this->assertAvailableDisplayPlugins($this->file, ['entity_reference:entity_reference_label', 'entity_reference:entity_reference_entity_id', 'file:file_default', 'file:file_table', 'file:file_url_plain']);
// Ensure that correct form attributes are returned for the file field
// formatter plugins.
$form = array();
$form_state = new FormState();
$plugins = array('file:file_table', 'file:file_default', 'file:file_url_plain');
// Ensure that description field is available for all the 'file' plugins.
foreach ($plugins as $plugin) {
$display = $this->displayPluginManager()->createInstance($plugin, array());
$display->setContextValue('entity', $this->file);
$conf_form = $display->buildConfigurationForm($form, $form_state);
$this->assertIdentical(array_keys($conf_form), array('description'));
$this->assertIdentical($conf_form['description']['#type'], 'textfield');
$this->assertIdentical((string) $conf_form['description']['#title'], 'Description');
}
// Test entity embed using 'Generic file' Entity Embed Display plugin.
$embed_settings = array('description' => "This is sample description");
$content = '<drupal-entity data-entity-type="file" data-entity-uuid="' . $this->file->uuid() . '" data-entity-embed-display="file:file_default" data-entity-embed-settings=\'' . Json::encode($embed_settings) . '\'>This placeholder should not be rendered.</drupal-entity>';
$settings = array();
$settings['type'] = 'page';
$settings['title'] = 'Test entity embed with file:file_default';
$settings['body'] = array(array('value' => $content, 'format' => 'custom_format'));
$node = $this->drupalCreateNode($settings);
$this->drupalGet('node/' . $node->id());
$this->assertText($embed_settings['description'], 'Description of the embedded file exists in page.');
$this->assertNoText(strip_tags($content), 'Placeholder does not appears in the output when embed is successful.');
$this->assertLinkByHref(file_create_url($this->file->getFileUri()), 0, 'Link to the embedded file exists.');
}
示例5: messageHandler
/**
* @todo .
*/
public function messageHandler()
{
if (!isset($_POST['serviceKey']) || !nodejs_is_valid_service_key($_POST['serviceKey'])) {
return new JsonResponse(array('error' => 'Invalid service key.'));
}
if (!isset($_POST['messageJson'])) {
return new JsonResponse(array('error' => 'No message.'));
}
$message = Json::decode($_POST['messageJson']);
$response = array();
switch ($message['messageType']) {
case 'authenticate':
$response = nodejs_auth_check($message);
break;
case 'userOffline':
nodejs_user_set_offline($message['uid']);
break;
default:
$handlers = array();
foreach (module_implements('nodejs_message_callback') as $module) {
$function = $module . '_nodejs_message_callback';
$handlers += $function($message['messageType']);
}
foreach ($handlers as $callback) {
$callback($message, $response);
}
}
\Drupal::moduleHandler()->alter('nodejs_message_response', $response, $message);
return new JsonResponse($response ? $response : array('error' => 'Not implemented'));
}
示例6: testRead
/**
* Tests several valid and invalid read requests on all entity types.
*/
public function testRead()
{
// @todo Expand this at least to users.
// Define the entity types we want to test.
$entity_types = array('entity_test', 'node');
foreach ($entity_types as $entity_type) {
$this->enableService('entity:' . $entity_type, 'GET');
// Create a user account that has the required permissions to read
// resources via the REST API.
$permissions = $this->entityPermissions($entity_type, 'view');
$permissions[] = 'restful get entity:' . $entity_type;
$account = $this->drupalCreateUser($permissions);
$this->drupalLogin($account);
// Create an entity programmatically.
$entity = $this->entityCreate($entity_type);
$entity->save();
// Read it over the REST API.
$response = $this->httpRequest($entity->getSystemPath(), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse('200', 'HTTP response code is correct.');
$this->assertHeader('content-type', $this->defaultMimeType);
$data = Json::decode($response);
// Only assert one example property here, other properties should be
// checked in serialization tests.
$this->assertEqual($data['uuid'][0]['value'], $entity->uuid(), 'Entity UUID is correct');
// Try to read the entity with an unsupported mime format.
$response = $this->httpRequest($entity->getSystemPath(), 'GET', NULL, 'application/wrongformat');
$this->assertResponse(200);
$this->assertHeader('Content-type', 'text/html; charset=UTF-8');
// Try to read an entity that does not exist.
$response = $this->httpRequest($entity_type . '/9999', 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(404);
$path = $entity_type == 'node' ? '/node/{node}' : '/entity_test/{entity_test}';
$expected_message = Json::encode(['error' => 'A fatal error occurred: The "' . $entity_type . '" parameter was not converted for the path "' . $path . '" (route name: "rest.entity.' . $entity_type . '.GET.hal_json")']);
$this->assertIdentical($expected_message, $response, 'Response message is correct.');
// Make sure that field level access works and that the according field is
// not available in the response. Only applies to entity_test.
// @see entity_test_entity_field_access()
if ($entity_type == 'entity_test') {
$entity->field_test_text->value = 'no access value';
$entity->save();
$response = $this->httpRequest($entity->getSystemPath(), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(200);
$this->assertHeader('content-type', $this->defaultMimeType);
$data = Json::decode($response);
$this->assertFalse(isset($data['field_test_text']), 'Field access protected field is not visible in the response.');
}
// Try to read an entity without proper permissions.
$this->drupalLogout();
$response = $this->httpRequest($entity->getSystemPath(), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(403);
$this->assertIdentical('{}', $response);
}
// Try to read a resource which is not REST API enabled.
$account = $this->drupalCreateUser();
$this->drupalLogin($account);
$response = $this->httpRequest($account->getSystemPath(), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(404);
$expected_message = Json::encode(['error' => 'A fatal error occurred: Unable to find the controller for path "/user/4". Maybe you forgot to add the matching route in your routing configuration?']);
$this->assertIdentical($expected_message, $response);
}
示例7: testPiwikCustomVariables
/**
* Tests if custom variables are properly added to the page.
*/
public function testPiwikCustomVariables()
{
$site_id = '3';
$this->config('piwik.settings')->set('site_id', $site_id)->save();
$this->config('piwik.settings')->set('url_http', 'http://www.example.com/piwik/')->save();
$this->config('piwik.settings')->set('url_https', 'https://www.example.com/piwik/')->save();
// Basic test if the feature works.
$custom_vars = [1 => ['slot' => 1, 'name' => 'Foo 1', 'value' => 'Bar 1', 'scope' => 'visit'], 2 => ['slot' => 2, 'name' => 'Foo 2', 'value' => 'Bar 2', 'scope' => 'page'], 3 => ['slot' => 3, 'name' => 'Foo 3', 'value' => 'Bar 3', 'scope' => 'page'], 4 => ['slot' => 4, 'name' => 'Foo 4', 'value' => 'Bar 4', 'scope' => 'visit'], 5 => ['slot' => 5, 'name' => 'Foo 5', 'value' => 'Bar 5', 'scope' => 'visit']];
$this->config('piwik.settings')->set('custom.variable', $custom_vars)->save();
$this->drupalGet('');
foreach ($custom_vars as $slot) {
$this->assertRaw('_paq.push(["setCustomVariable", ' . Json::encode($slot['slot']) . ', ' . Json::encode($slot['name']) . ', ' . Json::encode($slot['value']) . ', ' . Json::encode($slot['scope']) . ']);', '[testPiwikCustomVariables]: setCustomVariable ' . $slot['slot'] . ' is shown.');
}
// Test whether tokens are replaced in custom variable names.
$site_slogan = $this->randomMachineName(16);
$this->config('system.site')->set('slogan', $site_slogan)->save();
$custom_vars = [1 => ['slot' => 1, 'name' => 'Name: [site:slogan]', 'value' => 'Value: [site:slogan]', 'scope' => 'visit'], 2 => ['slot' => 2, 'name' => '', 'value' => $this->randomMachineName(16), 'scope' => 'page'], 3 => ['slot' => 3, 'name' => $this->randomMachineName(16), 'value' => '', 'scope' => 'visit'], 4 => ['slot' => 4, 'name' => '', 'value' => '', 'scope' => 'page'], 5 => ['slot' => 5, 'name' => '', 'value' => '', 'scope' => 'visit']];
$this->config('piwik.settings')->set('custom.variable', $custom_vars)->save();
$this->verbose('<pre>' . print_r($custom_vars, TRUE) . '</pre>');
$this->drupalGet('');
$this->assertRaw('_paq.push(["setCustomVariable", 1, ' . Json::encode("Name: {$site_slogan}") . ', ' . Json::encode("Value: {$site_slogan}") . ', "visit"]', '[testPiwikCustomVariables]: Tokens have been replaced in custom variable.');
$this->assertNoRaw('_paq.push(["setCustomVariable", 2,', '[testPiwikCustomVariables]: Value with empty name is not shown.');
$this->assertNoRaw('_paq.push(["setCustomVariable", 3,', '[testPiwikCustomVariables]: Name with empty value is not shown.');
$this->assertNoRaw('_paq.push(["setCustomVariable", 4,', '[testPiwikCustomVariables]: Empty name and value is not shown.');
$this->assertNoRaw('_paq.push(["setCustomVariable", 5,', '[testPiwikCustomVariables]: Empty name and value is not shown.');
}
示例8: testWatchdog
/**
* Writes a log messages and retrieves it via the REST API.
*/
public function testWatchdog()
{
// Write a log message to the DB.
$this->container->get('logger.channel.rest')->notice('Test message');
// Get the ID of the written message.
$id = db_query_range("SELECT wid FROM {watchdog} WHERE type = :type ORDER BY wid DESC", 0, 1, array(':type' => 'rest'))->fetchField();
// Create a user account that has the required permissions to read
// the watchdog resource via the REST API.
$account = $this->drupalCreateUser(array('restful get dblog'));
$this->drupalLogin($account);
$response = $this->httpRequest(Url::fromRoute('rest.dblog.GET.' . $this->defaultFormat, ['id' => $id, '_format' => $this->defaultFormat]), 'GET');
$this->assertResponse(200);
$this->assertHeader('content-type', $this->defaultMimeType);
$log = Json::decode($response);
$this->assertEqual($log['wid'], $id, 'Log ID is correct.');
$this->assertEqual($log['type'], 'rest', 'Type of log message is correct.');
$this->assertEqual($log['message'], 'Test message', 'Log message text is correct.');
// Request an unknown log entry.
$response = $this->httpRequest(Url::fromRoute('rest.dblog.GET.' . $this->defaultFormat, ['id' => 9999, '_format' => $this->defaultFormat]), 'GET');
$this->assertResponse(404);
$decoded = Json::decode($response);
$this->assertEqual($decoded['message'], 'Log entry with ID 9999 was not found', 'Response message is correct.');
// Make a bad request (a true malformed request would never be a route match).
$response = $this->httpRequest(Url::fromRoute('rest.dblog.GET.' . $this->defaultFormat, ['id' => 0, '_format' => $this->defaultFormat]), 'GET');
$this->assertResponse(400);
$decoded = Json::decode($response);
$this->assertEqual($decoded['message'], 'No log entry ID was provided', 'Response message is correct.');
}
示例9: testAjaxView
/**
* Tests an ajax view.
*/
public function testAjaxView()
{
$this->drupalGet('test_ajax_view');
$drupal_settings = $this->getDrupalSettings();
$this->assertTrue(isset($drupal_settings['views']['ajax_path']), 'The Ajax callback path is set in drupalSettings.');
$this->assertEqual(count($drupal_settings['views']['ajaxViews']), 1);
$view_entry = array_keys($drupal_settings['views']['ajaxViews'])[0];
$this->assertEqual($drupal_settings['views']['ajaxViews'][$view_entry]['view_name'], 'test_ajax_view', 'The view\'s ajaxViews array entry has the correct \'view_name\' key.');
$this->assertEqual($drupal_settings['views']['ajaxViews'][$view_entry]['view_display_id'], 'page_1', 'The view\'s ajaxViews array entry has the correct \'view_display_id\' key.');
$data = array();
$data['view_name'] = 'test_ajax_view';
$data['view_display_id'] = 'test_ajax_view';
$post = array('view_name' => 'test_ajax_view', 'view_display_id' => 'page_1');
$post += $this->getAjaxPageStatePostData();
$response = $this->drupalPost('views/ajax', 'application/vnd.drupal-ajax', $post);
$data = Json::decode($response);
$this->assertTrue(isset($data[0]['settings']['views']['ajaxViews']));
$this->assertEqual($data[1]['command'], 'add_css');
// Ensure that the view insert command is part of the result.
$this->assertEqual($data[2]['command'], 'insert');
$this->assertTrue(strpos($data[2]['selector'], '.js-view-dom-id-') === 0);
$this->setRawContent($data[2]['data']);
$result = $this->xpath('//div[contains(@class, "views-row")]');
$this->assertEqual(count($result), 2, 'Ensure that two items are rendered in the HTML.');
}
示例10: selectCondition
/**
* Presents a list of conditions to add to the block_visibility_group entity.
*
* @param \Drupal\block_visibility_groups\Entity\BlockVisibilityGroup $block_visibility_group
* The block_visibility_group entity.
*
* @return array
* The condition selection page.
*/
public function selectCondition(BlockVisibilityGroup $block_visibility_group, $redirect) {
$build = [
'#theme' => 'links',
'#links' => [],
];
$available_plugins = $this->conditionManager->getDefinitions();
// @todo Should nesting Conditions be allowed
unset($available_plugins['condition_group']);
foreach ($available_plugins as $condition_id => $condition) {
$build['#links'][$condition_id] = [
'title' => $condition['label'],
'url' => Url::fromRoute('block_visibility_groups.condition_add', [
'block_visibility_group' => $block_visibility_group->id(),
'condition_id' => $condition_id,
'redirect' => $redirect,
]),
'attributes' => [
'class' => ['use-ajax'],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 'auto',
]),
],
];
}
return $build;
}
示例11: decodeRequest
/**
* Attempts to decode the incoming request's content as JSON.
*
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return mixed
*
* @throws \Drupal\panels_ipe\Exception\EmptyRequestContentException
*/
protected static function decodeRequest(Request $request)
{
if (empty($request->getContent())) {
throw new EmptyRequestContentException();
}
return Json::decode($request->getContent());
}
示例12: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$form_state->cleanValues();
// This won't have a proper JSON header, but Drupal doesn't check for that
// anyway so this is fine until it's replaced with a JsonResponse.
print Json::encode($form_state->getValues());
exit;
}
示例13: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state)
{
form_state_values_clean($form_state);
// This won't have a proper JSON header, but Drupal doesn't check for that
// anyway so this is fine until it's replaced with a JsonResponse.
print Json::encode($form_state['values']);
exit;
}
示例14: render
/**
* {@inheritdoc}
*/
public function render(array $js_assets)
{
$elements = array();
// A dummy query-string is added to filenames, to gain control over
// browser-caching. The string changes on every update or full cache
// flush, forcing browsers to load a new copy of the files, as the
// URL changed. Files that should not be cached (see _drupal_add_js())
// get REQUEST_TIME as query-string instead, to enforce reload on every
// page request.
$default_query_string = $this->state->get('system.css_js_query_string') ?: '0';
// For inline JavaScript to validate as XHTML, all JavaScript containing
// XHTML needs to be wrapped in CDATA. To make that backwards compatible
// with HTML 4, we need to comment out the CDATA-tag.
$embed_prefix = "\n<!--//--><![CDATA[//><!--\n";
$embed_suffix = "\n//--><!]]>\n";
// Defaults for each SCRIPT element.
$element_defaults = array('#type' => 'html_tag', '#tag' => 'script', '#value' => '');
// Loop through all JS assets.
foreach ($js_assets as $js_asset) {
// Element properties that do not depend on JS asset type.
$element = $element_defaults;
$element['#browsers'] = $js_asset['browsers'];
// Element properties that depend on item type.
switch ($js_asset['type']) {
case 'setting':
$element['#value_prefix'] = $embed_prefix;
$element['#value'] = 'var drupalSettings = ' . Json::encode(drupal_merge_js_settings($js_asset['data'])) . ";";
$element['#value_suffix'] = $embed_suffix;
break;
case 'inline':
$element['#value_prefix'] = $embed_prefix;
$element['#value'] = $js_asset['data'];
$element['#value_suffix'] = $embed_suffix;
break;
case 'file':
$query_string = empty($js_asset['version']) ? $default_query_string : 'v=' . $js_asset['version'];
$query_string_separator = strpos($js_asset['data'], '?') !== FALSE ? '&' : '?';
$element['#attributes']['src'] = file_create_url($js_asset['data']);
// Only add the cache-busting query string if this isn't an aggregate
// file.
if (!isset($js_asset['preprocessed'])) {
$element['#attributes']['src'] .= $query_string_separator . ($js_asset['cache'] ? $query_string : REQUEST_TIME);
}
break;
case 'external':
$element['#attributes']['src'] = $js_asset['data'];
break;
default:
throw new \Exception('Invalid JS asset type.');
}
// Attributes may only be set if this script is output independently.
if (!empty($element['#attributes']['src']) && !empty($js_asset['attributes'])) {
$element['#attributes'] += $js_asset['attributes'];
}
$elements[] = $element;
}
return $elements;
}
示例15: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$form = parent::form($form, $form_state);
$form['use_admin_theme'] = ['#type' => 'checkbox', '#title' => $this->t('Use admin theme'), '#default_value' => $this->entity->usesAdminTheme()];
$attributes = ['class' => ['use-ajax'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 'auto'])];
$add_button_attributes = NestedArray::mergeDeep($attributes, ['class' => ['button', 'button--small', 'button-action']]);
$form['context'] = ['#type' => 'details', '#title' => $this->t('Available context'), '#open' => TRUE];
$form['context']['add'] = ['#type' => 'link', '#title' => $this->t('Add new static context'), '#url' => Url::fromRoute('page_manager.static_context_add', ['page' => $this->entity->id()]), '#attributes' => $add_button_attributes, '#attached' => ['library' => ['core/drupal.ajax']]];
$form['context']['available_context'] = ['#type' => 'table', '#header' => [$this->t('Label'), $this->t('Name'), $this->t('Type'), $this->t('Operations')], '#empty' => $this->t('There is no available context.')];
$contexts = $this->entity->getContexts();
foreach ($contexts as $name => $context) {
$context_definition = $context->getContextDefinition();
$row = [];
$row['label'] = ['#markup' => $context_definition->getLabel()];
$row['machine_name'] = ['#markup' => $name];
$row['type'] = ['#markup' => $context_definition->getDataType()];
// Add operation links if the context is a static context.
$operations = [];
if ($this->entity->getStaticContext($name)) {
$operations['edit'] = ['title' => $this->t('Edit'), 'url' => Url::fromRoute('page_manager.static_context_edit', ['page' => $this->entity->id(), 'name' => $name]), 'attributes' => $attributes];
$operations['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('page_manager.static_context_delete', ['page' => $this->entity->id(), 'name' => $name]), 'attributes' => $attributes];
}
$row['operations'] = ['#type' => 'operations', '#links' => $operations];
$form['context']['available_context'][$name] = $row;
}
$form['display_variant_section'] = ['#type' => 'details', '#title' => $this->t('Display variants'), '#open' => TRUE];
$form['display_variant_section']['add_new_page'] = ['#type' => 'link', '#title' => $this->t('Add new display variant'), '#url' => Url::fromRoute('page_manager.display_variant_select', ['page' => $this->entity->id()]), '#attributes' => $add_button_attributes, '#attached' => ['library' => ['core/drupal.ajax']]];
$form['display_variant_section']['display_variants'] = ['#type' => 'table', '#header' => [$this->t('Label'), $this->t('Plugin'), $this->t('Weight'), $this->t('Operations')], '#empty' => $this->t('There are no display variants.'), '#tabledrag' => [['action' => 'order', 'relationship' => 'sibling', 'group' => 'display-variant-weight']]];
foreach ($this->entity->getVariants() as $display_variant_id => $display_variant) {
$row = ['#attributes' => ['class' => ['draggable']]];
$row['label']['#markup'] = $display_variant->label();
$row['id']['#markup'] = $display_variant->adminLabel();
$row['weight'] = ['#type' => 'weight', '#default_value' => $display_variant->getWeight(), '#title' => $this->t('Weight for @display_variant display variant', ['@display_variant' => $display_variant->label()]), '#title_display' => 'invisible', '#attributes' => ['class' => ['display-variant-weight']]];
$operations = [];
$operations['edit'] = ['title' => $this->t('Edit'), 'url' => Url::fromRoute('page_manager.display_variant_edit', ['page' => $this->entity->id(), 'display_variant_id' => $display_variant_id])];
$operations['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('page_manager.display_variant_delete', ['page' => $this->entity->id(), 'display_variant_id' => $display_variant_id])];
$row['operations'] = ['#type' => 'operations', '#links' => $operations];
$form['display_variant_section']['display_variants'][$display_variant_id] = $row;
}
if ($access_conditions = $this->entity->getAccessConditions()) {
$form['access_section_section'] = ['#type' => 'details', '#title' => $this->t('Access Conditions'), '#open' => TRUE];
$form['access_section_section']['add'] = ['#type' => 'link', '#title' => $this->t('Add new access condition'), '#url' => Url::fromRoute('page_manager.access_condition_select', ['page' => $this->entity->id()]), '#attributes' => $add_button_attributes, '#attached' => ['library' => ['core/drupal.ajax']]];
$form['access_section_section']['access_section'] = ['#type' => 'table', '#header' => [$this->t('Label'), $this->t('Description'), $this->t('Operations')], '#empty' => $this->t('There are no access conditions.')];
$form['access_section_section']['access_logic'] = ['#type' => 'radios', '#options' => ['and' => $this->t('All conditions must pass'), 'or' => $this->t('Only one condition must pass')], '#default_value' => $this->entity->getAccessLogic()];
$form['access_section_section']['access'] = ['#tree' => TRUE];
foreach ($access_conditions as $access_id => $access_condition) {
$row = [];
$row['label']['#markup'] = $access_condition->getPluginDefinition()['label'];
$row['description']['#markup'] = $access_condition->summary();
$operations = [];
$operations['edit'] = ['title' => $this->t('Edit'), 'url' => Url::fromRoute('page_manager.access_condition_edit', ['page' => $this->entity->id(), 'condition_id' => $access_id]), 'attributes' => $attributes];
$operations['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('page_manager.access_condition_delete', ['page' => $this->entity->id(), 'condition_id' => $access_id]), 'attributes' => $attributes];
$row['operations'] = ['#type' => 'operations', '#links' => $operations];
$form['access_section_section']['access_section'][$access_id] = $row;
}
}
return $form;
}