TslAssessment - PHP Online
Form of PHP Sandbox
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of TslAssessment.php
- <?php
- namespace Drupal\tsl_assessment_ui;
- use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
- use Drupal\Core\Entity\EntityTypeManagerInterface;
- use Drupal\Core\Link;
- use Drupal\Core\Session\AccountProxy;
- use Drupal\Core\Url;
- use Drupal\tsl_assessment\factory\AssessmentFactory;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- class TslAssessmentLinkGenerator implements ContainerInjectionInterface {
- protected $factory;
- protected $entityTypeManager;
- protected $currentUser;
- public function __construct(AssessmentFactory $assessment_factory, EntityTypeManagerInterface $entity_type_manager, AccountProxy $account_proxy) {
- $this->factory = $assessment_factory;
- $this->entityTypeManager = $entity_type_manager;
- $this->currentUser = $account_proxy;
- }
- public static function create(ContainerInterface $container) {
- return new static(
- $container->get('tsl_assessment.assessment_factory'),
- $container->get('entity_type.manager'),
- $container->get('current_user')
- );
- }
- /**
- * Generate link to Assessment submission page by Assessment id.
- *
- * @param $assessment_id
- *
- * @return \Drupal\Core\GeneratedLink|string|null
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- public function tsl_assessment_ui_get_submit_link($assessment_id) {
- $route_name = 'view.assessment_start_submission_page.page_start_assessment';
- $is_access = Url::fromRoute($route_name, ['tsl_schd_assessment' => $assessment_id])->access();
- $assessment = $this->entityTypeManager->getStorage('tsl_schd_assessment')->load($assessment_id);
- $subject = $this->entityTypeManager->getStorage('user')->load($this->currentUser->id());
- $status = $this->factory->getAssessmentManager($assessment)->getStatus($subject);
- $user_access = $this->factory->getUserAccess();
- if (!$is_access || !$user_access->isAdmin() && $user_access->isOrgSubject() && $status == TSL_ASSESSMENT_STATUS_REPORT_CREATED) {
- return $assessment->label();
- }
- return Link::createFromRoute(
- $assessment->label(),
- $route_name,
- ['tsl_schd_assessment' => $assessment_id]
- )->toString();
- }
- }