diff --git a/src/PathautoState.php b/src/PathautoState.php
index 16b8a26..5cb162f 100644
--- a/src/PathautoState.php
+++ b/src/PathautoState.php
@@ -39,34 +39,16 @@ class PathautoState extends TypedData {
    */
   public function getValue() {
     if ($this->value === NULL) {
-      $entity = $this->parent->getEntity();
-
-      // @todo: Investigate why this happens.
-      if ($entity->isNew()) {
-        $this->value = static::CREATE;
-        return $this->value;
-      }
-
       // If no value has been set or loaded yet, try to load a value if this
       // entity has already been saved.
       $this->value = \Drupal::keyValue($this->getCollection())
         ->get($this->parent->getEntity()->id());
-      // If it was not yet saved or no value was found, try to detect based on
-      // an existing alias if the entity is not new.
+      // If it was not yet saved or no value was found, then set the flag to
+      // create the alias if there is a matching pattern.
       if ($this->value === NULL) {
-        $entity_path = '/' . $entity->toUrl()->getInternalPath();
-        $path = \Drupal::service('path.alias_manager')
-          ->getAliasByPath(
-            $entity_path, $entity->language()->getId()
-          );
-        $pathauto_alias = \Drupal::service('pathauto.generator')
-          ->createEntityAlias($entity, 'return');
-        if (($path != $entity_path && $path == $pathauto_alias)) {
-          $this->value = static::CREATE;
-        }
-        else {
-          $this->value = static::SKIP;
-        }
+        $entity = $this->parent->getEntity();
+        $pattern = \Drupal::service('pathauto.generator')->getPatternByEntity($entity);
+        $this->value = !empty($pattern) ? static::CREATE : static::SKIP;
       }
     }
     return $this->value;
diff --git a/src/Tests/PathautoBulkUpdateTest.php b/src/Tests/PathautoBulkUpdateTest.php
index 149ae9b..353f5b1 100644
--- a/src/Tests/PathautoBulkUpdateTest.php
+++ b/src/Tests/PathautoBulkUpdateTest.php
@@ -80,7 +80,7 @@ class PathautoBulkUpdateTest extends WebTestBase {
     // This has generated 6 aliases. 5 nodes and one user that we created. There
     // is also UID 1 but that user was created before the path field existed,
     // so he does not have a pathauto state.
-    $this->assertText('Generated 6 URL aliases.');
+    $this->assertText('Generated 7 URL aliases.');
 
     // Check that aliases have actually been created.
     foreach ($this->nodes as $node) {
@@ -97,4 +97,28 @@ class PathautoBulkUpdateTest extends WebTestBase {
 
     $this->assertNoEntityAliasExists($new_node);
   }
+
+  /**
+   * Tests alias generation for nodes that existed before installing Pathauto.
+   */
+  function testBulkUpdateExistingContent() {
+    // Create a node.
+    $node = $this->drupalCreateNode();
+
+    // Delete its alias and Pathauto metadata.
+    \Drupal::service('pathauto.alias_storage_helper')->deleteEntityPathAll($node);
+    $node->path->first()->get('pathauto')->purge();
+    \Drupal::entityManager()->getStorage('node')->resetCache(array($node->id()));
+
+    // Execute bulk generation.
+    // Bulk create aliases.
+    $edit = array(
+      'update[canonical_entities:node]' => TRUE,
+    );
+    $this->drupalPostForm('admin/config/search/path/update_bulk', $edit, t('Update'));
+
+    // Verify that the alias was created for the node.
+    $this->assertText('Generated 1 URL alias.');
+  }
+
 }
diff --git a/src/Tests/PathautoNodeWebTest.php b/src/Tests/PathautoNodeWebTest.php
index 83a3fb5..abbd3a7 100644
--- a/src/Tests/PathautoNodeWebTest.php
+++ b/src/Tests/PathautoNodeWebTest.php
@@ -253,4 +253,39 @@ class PathautoNodeWebTest extends WebTestBase {
     $this->assertNull(\Drupal::keyValue('pathauto_state.node')->get($node->id()), 'Pathauto state was deleted');
   }
 
+
+  /**
+   * Tests that nodes without a Pathauto pattern can set custom aliases.
+   */
+  public function testCustomAliasWithoutPattern() {
+    // First, delete all patterns to be sure that there will be no match.
+    $entity_ids = \Drupal::entityQuery('pathauto_pattern')->execute();
+    $entities = PathautoPattern::loadMultiple($entity_ids);
+    foreach ($entities as $entity) {
+      $entity->delete();
+    }
+
+    // Next, create a node with a custom alias.
+    $edit = [
+      'title[0][value]' => 'Sample article',
+      'path[0][alias]' => '/sample-article',
+    ];
+    $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
+    $this->assertText(t('article Sample article has been created.'));
+
+    // Test the alias.
+    $this->assertAliasExists(array('alias' => '/sample-article'));
+    $this->drupalGet('sample-article');
+    $this->assertResponse(200, 'A node without a pattern can have a custom alias.');
+
+    // Now create a node through the API.
+    $node = Node::create(['type' => 'article', 'title' => 'Sample article API', 'path' => ['alias' => '/sample-article-api']]);
+    $node->save();
+
+    // Test the alias.
+    $this->assertAliasExists(['alias' => '/sample-article-api']);
+    $this->drupalGet('sample-article-api');
+    $this->assertResponse(200);
+  }
+
 }
