<commit_before><?php

class dmAdminLinkTag extends dmBaseLinkTag
{
  protected
  $serviceContainer;
  
  public function __construct($resource, dmAdminBaseServiceContainer $serviceContainer, array $options)
  {
    $this->resource         = empty($resource) ? '@homepage' : $resource;
    $this->serviceContainer = $serviceContainer;
    
    $this->initialize($options);
  }
  
  public function render()
  {
    try
    {
      return parent::render();
    }
    catch(Exception $e)
    {
      return '<a class="link">'.$e->getMessage().'</a>';
    }
  }

  protected function getBaseHref()
  {
    if(is_string($this->resource))
    {
      $resource = $this->resource;
      /*
       * If a blank space is found in the source,
       * remove characters after it
       * because they are just a comment
       * ex : page:1?var=val Home
       */
      if ($blankSpacePos = strpos($resource, ' '))
      {
        $resource = substr($resource, 0, $blankSpacePos);
      }
      if (strncmp($resource, 'page:', 5) === 0)
      {
        $pageResource = preg_replace('|^(page:\d+).*$|', '$1', $resource);
        
        if ($page = dmDb::table('DmPage')->findOneBySource($pageResource))
        {
          $this->resource = preg_replace('|^page:\d+(.*)$|', 'app:front/'.$page->slug.'$1', $resource);
        }
        else
        {
          throw new dmException(sprintf('%s is not a valid link resource', $resource));
        }
      }
      elseif(strncmp($resource, 'media:', 6) === 0)
      {
        $mediaResource = preg_replace('|^media:(\d+).*|', '$1', $resource);
        
        if ($media = dmDb::table('DmMedia')->findOneByIdWithFolder($mediaResource))
        {
          $resource = '/'.$media->getWebPath();
          /*
           * add relativeUrlRoot to absolute resource
           */
          if($relativeUrlRoot = dmArray::get($this->serviceContainer->getParameter('request.context'), 'relative_url_root'))
          {
            $resource = $relativeUrlRoot.$resource;
          }
        }
        else
        {
          throw new dmException(sprintf('%s is not a valid media resource. The media with id %s does not exist', $resource, $mediaResource));
        }
      }
      elseif (strncmp($this->resource, 'app:', 4) === 0)
      {
        $type = 'uri';<commit_msg>fix bug with page links in admin forms<commit_after><?php

class dmAdminLinkTag extends dmBaseLinkTag
{
  protected
  $serviceContainer;
  
  public function __construct($resource, dmAdminBaseServiceContainer $serviceContainer, array $options)
  {
    $this->resource         = empty($resource) ? '@homepage' : $resource;
    $this->serviceContainer = $serviceContainer;
    
    $this->initialize($options);
  }
  
  public function render()
  {
    try
    {
      return parent::render();
    }
    catch(Exception $e)
    {
      return '<a class="link">'.$e->getMessage().'</a>';
    }
  }

  protected function getBaseHref()
  {
    if(is_string($this->resource))
    {
      $resource = $this->resource;
      
      /**
       * If a blank space is found in the source,
       * remove characters after it
       * because they are just a comment
       * ex : page:1?var=val Home
       */
      if ($blankSpacePos = strpos($resource, ' '))
      {
        $resource = substr($resource, 0, $blankSpacePos);
      }
      
      if (strncmp($resource, 'page:', 5) === 0)
      {
        $pageResource = preg_replace('|^(page:\d+).*$|', '$1', $resource);
        
        if ($page = dmDb::table('DmPage')->findOneBySource($pageResource))
        {
          $resource = preg_replace('|^page:\d+(.*)$|', 'app:front/'.$page->slug.'$1', $resource);
        }
        else
        {
          throw new dmException(sprintf('%s is not a valid link resource', $resource));
        }
      }
      elseif(strncmp($resource, 'media:', 6) === 0)
      {
        $mediaResource = preg_replace('|^media:(\d+).*|', '$1', $resource);
        
        if ($media = dmDb::table('DmMedia')->findOneByIdWithFolder($mediaResource))
        {
          $resource = '/'.$media->getWebPath();
          /*
           * add relativeUrlRoot to absolute resource
           */
          if($relativeUrlRoot = dmArray::get($this->serviceContainer->getParameter('request.context'), 'relative_url_root'))
          {
            $resource = $relativeUrlRoot.$resource;
          }
        }
        else
        {
          throw new dmException(sprintf('%s is not a valid media resource. The media with id %s does not exist', $resource, $mediaResource));
        }
      }
      elseif (strncmp($this->resource, 'app:', 4) === 0)
      {
        $type = 'uri';
{'fraction_non_alphanumeric': 0.15978494623655914, 'fraction_numerical': 0.004731182795698925, 'mean_word_length': 2.2411149825783974, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '524511', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1385, 'n_words': 294}