hasDefault example

$package_name = $package->getName();
    $package_path = $this->getPackagePath($package);
    $prepend_source_file = NULL;
    $append_source_file = NULL;
    $default_data_file = NULL;
    if ($operation_data->hasPrepend()) {
      $prepend_source_file = ScaffoldFilePath::sourcePath($package_name$package_path$operation_data->destination()$operation_data->prepend());
    }
    if ($operation_data->hasAppend()) {
      $append_source_file = ScaffoldFilePath::sourcePath($package_name$package_path$operation_data->destination()$operation_data->append());
    }
    if ($operation_data->hasDefault()) {
      $default_data_file = ScaffoldFilePath::sourcePath($package_name$package_path$operation_data->destination()$operation_data->default());
    }
    if (!$this->hasContent($prepend_source_file) && !$this->hasContent($append_source_file)) {
      $message = ' - Keep <info>[dest-rel-path]</info> unchanged: no content to prepend / append was provided.';
      return new SkipOp($message);
    }

    return new AppendOp($prepend_source_file$append_source_file$operation_data->forceAppend()$default_data_file);
  }

  /** * Checks to see if the specified scaffold file exists and has content. * * @param \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath $file * Scaffold file to check. * * @return bool * True if the file exists and has content. */
// Ensure that the test_route is overridden.     $route = $collection->get('test_route');
    $this->assertInstanceOf(Route::class$route);
    $this->assertEquals('test_id', $route->getDefault('view_id'));
    $this->assertEquals('page_1', $route->getDefault('display_id'));
    $this->assertEquals('Drupal\views\Routing\ViewPageController::getTitle', $route->getDefault('_title_callback'));

    // Ensure that the test_route_2 is not overridden.     $route = $collection->get('test_route_2');
    $this->assertInstanceOf(Route::class$route);
    $this->assertFalse($route->hasDefault('view_id'));
    $this->assertFalse($route->hasDefault('display_id'));
    $this->assertSame($collection->get('test_route_2')$route_2);
  }

  /** * Tests the altering of a REST route. */
  public function testAlterPostRestRoute() {
    $collection = new RouteCollection();
    $route = new Route('test_route', ['_controller' => 'Drupal\Tests\Core\Controller\TestController::content']);
    $route->setMethods(['POST']);
    
if ($pos < \strlen($pattern)) {
            $tokens[] = ['text', substr($pattern$pos)];
        }

        // find the first optional token         $firstOptional = \PHP_INT_MAX;
        if (!$isHost) {
            for ($i = \count($tokens) - 1; $i >= 0; --$i) {
                $token = $tokens[$i];
                // variable is optional when it is not important and has a default value                 if ('variable' === $token[0] && !($token[5] ?? false) && $route->hasDefault($token[3])) {
                    $firstOptional = $i;
                } else {
                    break;
                }
            }
        }

        // compute the matching regexp         $regexp = '';
        for ($i = 0, $nbToken = \count($tokens)$i < $nbToken; ++$i) {
            $regexp .= self::computeRegexp($tokens$i$firstOptional);
        }
$this->expectExceptionMessage('Document types are not allowed.');
        $loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
        $loader->load('withdoctype.xml');
    }

    public function testNullValues()
    {
        $loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
        $routeCollection = $loader->load('null_values.xml');
        $route = $routeCollection->get('blog_show');

        $this->assertTrue($route->hasDefault('foo'));
        $this->assertNull($route->getDefault('foo'));
        $this->assertTrue($route->hasDefault('bar'));
        $this->assertNull($route->getDefault('bar'));
        $this->assertEquals('foo', $route->getDefault('foobar'));
        $this->assertEquals('bar', $route->getDefault('baz'));
    }

    public function testScalarDataTypeDefaults()
    {
        $loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
        $routeCollection = $loader->load('scalar_defaults.xml');
        

  public function getTitle(Request $request, Route $route) {
    $route_title = NULL;
    // A dynamic title takes priority. Route::getDefault() returns NULL if the     // named default is not set. By testing the value directly, we also avoid     // trying to use empty values.     if ($callback = $route->getDefault('_title_callback')) {
      $callable = $this->controllerResolver->getControllerFromDefinition($callback);
      $arguments = $this->argumentResolver->getArguments($request$callable);
      $route_title = call_user_func_array($callable$arguments);
    }
    elseif ($route->hasDefault('_title') && strlen($route->getDefault('_title')) > 0) {
      $title = $route->getDefault('_title');
      $options = [];
      if ($route->hasDefault('_title_context')) {
        $options['context'] = $route->getDefault('_title_context');
      }
      $args = [];
      if (($raw_parameters = $request->attributes->get('_raw_variables'))) {
        foreach ($raw_parameters->all() as $key => $value) {
          if (is_scalar($value)) {
            $args['@' . $key] = $value;
            $args['%' . $key] = $value;
          }
class FormRouteEnhancer implements EnhancerInterface {

  /** * Returns whether the enhancer runs on the current route. * * @param \Symfony\Component\Routing\Route $route * The current route. * * @return bool */
  protected function applies(Route $route) {
    return $route->hasDefault('_form') && !$route->hasDefault('_controller');
  }

  /** * {@inheritdoc} */
  public function enhance(array $defaults, Request $request) {
    $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
    if (!$this->applies($route)) {
      return $defaults;
    }

    

  protected function overrideAppliesPathAndMethod($view_path, Route $view_route, Route $route) {
    // Find all paths which match the path of the current display..     $route_path = RouteCompiler::getPathWithoutDefaults($route);
    $route_path = RouteCompiler::getPatternOutline($route_path);

    // Ensure that we don't override a route which is already controlled by     // views.     return !$route->hasDefault('view_id')
    && ('/' . $view_path == $route_path)
    // Also ensure that we don't override for example REST routes.     && (!$route->getMethods() || in_array('GET', $route->getMethods()));
  }

  /** * {@inheritdoc} */
  public function alterRoutes(RouteCollection $collection) {
    $view_route_names = [];
    $view_path = $this->getPath();
    


  /** * Returns whether the enhancer runs on the current route. * * @param \Symfony\Component\Routing\Route $route * The current route. * * @return bool */
  protected function applies(Route $route) {
    return !$route->hasDefault('_controller') &&
      ($route->hasDefault('_entity_form')
        || $route->hasDefault('_entity_list')
        || $route->hasDefault('_entity_view')
      );
  }

  /** * Update defaults for entity forms. * * @param array $defaults * The defaults to modify. * @param \Symfony\Component\HttpFoundation\Request $request * The Request instance. * * @return array * The modified defaults. */


    $all_supported_methods = array_merge(...$all_supported_methods);
    $collection = $this->inner->filter($collection$request);

    if (!$this->readOnlyModeIsEnabled) {
      return $collection;
    }

    $read_only_methods = ['GET', 'HEAD', 'OPTIONS', 'TRACE'];
    foreach ($collection->all() as $name => $route) {
      if (!$route->hasDefault(Routes::JSON_API_ROUTE_FLAG_KEY)) {
        continue;
      }

      $supported_methods = $route->getMethods();
      assert(count($supported_methods) > 0, 'JSON:API routes always have a method specified.');
      $is_read_only_route = empty(array_diff($supported_methods$read_only_methods));
      if (!$is_read_only_route) {
        $collection->remove($name);
      }
    }
    if (count($collection)) {
      
$id_parts = explode('.', $id);
      $this->assertEquals($id_parts[1]$route->getDefault('view_id'));
      $this->assertEquals($id_parts[2]$route->getDefault('display_id'));
    }

    // Check the generated patterns and default values.     $route = $collection->get('view.test_page_display_route.page_1');
    $this->assertEquals('/test_route_without_arguments', $route->getPath());

    $route = $collection->get('view.test_page_display_route.page_2');
    $this->assertEquals('/test_route_with_argument/{arg_0}', $route->getPath());
    $this->assertTrue($route->hasDefault('arg_0'), 'A default value is set for the optional argument id.');

    $route = $collection->get('view.test_page_display_route.page_3');
    $this->assertEquals('/test_route_with_argument/{arg_0}/suffix', $route->getPath());
    $this->assertFalse($route->hasDefault('arg_0'), 'No default value is set for the required argument id.');

    $route = $collection->get('view.test_page_display_route.page_4');
    $this->assertEquals('/test_route_with_argument/{arg_0}/suffix/{arg_1}', $route->getPath());
    $this->assertFalse($route->hasDefault('arg_0'), 'No default value is set for the required argument id.');
    $this->assertTrue($route->hasDefault('arg_1'), 'A default value is set for the optional argument id_2.');

    $route = $collection->get('view.test_page_display_route.page_5');
    
if ($pos < \strlen($pattern)) {
            $tokens[] = ['text', substr($pattern$pos)];
        }

        // find the first optional token         $firstOptional = \PHP_INT_MAX;
        if (!$isHost) {
            for ($i = \count($tokens) - 1; $i >= 0; --$i) {
                $token = $tokens[$i];
                // variable is optional when it is not important and has a default value                 if ('variable' === $token[0] && !($token[5] ?? false) && $route->hasDefault($token[3])) {
                    $firstOptional = $i;
                } else {
                    break;
                }
            }
        }

        // compute the matching regexp         $regexp = '';
        for ($i = 0, $nbToken = \count($tokens)$i < $nbToken; ++$i) {
            $regexp .= self::computeRegexp($tokens$i$firstOptional);
        }

        $this->expectException(AccessException::class);
        $this->resolver->setDefault('lazy', function DOptions $options) {
            $options->setDefault('default', 42);
        });

        $this->resolver->resolve();
    }

    public function testHasDefault()
    {
        $this->assertFalse($this->resolver->hasDefault('foo'));
        $this->resolver->setDefault('foo', 42);
        $this->assertTrue($this->resolver->hasDefault('foo'));
    }

    public function testHasDefaultWithNullValue()
    {
        $this->assertFalse($this->resolver->hasDefault('foo'));
        $this->resolver->setDefault('foo', null);
        $this->assertTrue($this->resolver->hasDefault('foo'));
    }

    
public function overwrite() {
    return !empty($this->data[self::OVERWRITE]);
  }

  /** * Determines whether 'force-append' has been set. * * @return bool * Returns true if 'force-append' mode was selected. */
  public function forceAppend() {
    if ($this->hasDefault()) {
      return TRUE;
    }
    return !empty($this->data[self::FORCE_APPEND]);
  }

  /** * Checks if prepend path exists. * * @return bool * Returns true if prepend exists. */
  
Home | Imprint | This part of the site doesn't use cookies.